﻿/****************************************************************************
*                                                                           *
* Copyright (c) RSC. All rights reserved(2010).								*
* Developers: Marius Ionescu, Cristian Bojinovici     						*
*                                                                           *
****************************************************************************/

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
using System.Collections;
using System.Text;
using System.Web.Services;

public partial class CommonReports : SessionPageBase
{
    StringBuilder sb = new StringBuilder();

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!string.IsNullOrEmpty(Request.QueryString["info"]))
            {
                CommonSession.StareRapoarteLaborator info = CommonSession.GetParameterStareRL(this, Request.QueryString["info"]);

                switch (info.tipRaport)
                {
                    case "Imprimare Buletine": ImprimareBuletine(info);
                        break;

                    case "Registru Cercetare": ImprimareRegistruCercetare(info);
                        break;

                    case "genericDocs|Centralizer_Medics_Sections": CentralizationSectionMedics(info);
                        break;

                    case "genericDocs|registerStudyPrepare.asp": ImprimareRegistruCercetare(info);
                        break;

                    case "genericDocs|regPrimiri_prep.asp?report=regPrimiri": regPrimiri(info);
                        break;

                    case "genericDocs|registerStudyPrepare.asp?report=invList": ImprimareRegistruCercetare(info);
                        break;

                    case "genericDocs|regPrimiri_prep.asp?report=invListVarste": regPrimiriInvListVarste(info);
                        break;

                    case "genericDocs|regCereri": ImprimareRegistruCercetare(info);
                        break;

                    case "casLPrivat|listCASPrivateLabsPrepare.asp": CASLPrivat(info);
                        break;

                    case "casLPrivat|nominalCASPrivateLabsDetailPrepare.asp": nominalCASPrivate(info);
                        break;

                    case "casGeneric|centralizerCAS_VALPrepare.asp": centralizerCAS_VAL(info);
                        break;

                    case "casGeneric|centralizerCASPrepare.asp": centralizerCAS(info);
                        break;

                    case "casGeneric|listCASPrepare.asp": listCAS(info);
                        break;

                    case "casGeneric|nominalCASPrepare.asp": nominalCAS(info);
                        break;

                    case "casAmbulator|listAMBPrepare.asp": listAMBP(info);
                        break;

                    case "casAmbulator|nominalAMBPrepare.asp": nominalAMBP(info);
                        break;

                    case "casAmbulator|nominalAMBDetailPrepare.asp": nominalAMBDetail(info);
                        break;

                    case "misc|generalFilePrepareSecMe.asp": generalFilePrepareSecMe(info);
                        break;

                    case "misc|generalFilePrepareSecMeAn.asp": generalFilePrepareSecMeAn(info);
                        break;

                    case "misc|generalFilePrepareSecMeAnDet.asp": generalFilePrepareSecMeAnDet(info);
                        break;

                    case "misc|generalFilePrepareAnSecMe.asp": generalFilePrepareAnSecMe(info);
                        break;

                    case "misc|generalFilePrepareAnSecMeDet.asp": generalFilePrepareAnSecMeDet(info);
                        break;

                    case "misc|ClassSecMeDet.asp": ClassSecMeDet(info);
                        break;

                    default:
                        break;
                }
            }
            else
                this.SetMessage("Session expired", false);
        }
        catch (Exception ex)
        {
            message.Text = ex.ToString();
        }
    }

    protected string siglaRSC()
    {
        return "<a href=\"..\\ReportsLaboratory.aspx\">sistem informatic HIPOCRATE<br/>@RSC<br/>E-mail: office@rsc.ro</span></a>";
    }

    protected void ImprimareBuletine(CommonSession.StareRapoarteLaborator info)
    {
        try
        {
            SortedDictionary<int, string> sortedData = new SortedDictionary<int, string>();
            string[] arrFields;

            string querystring = "select distinct RequestID from vRequestClass where 1=1 ";

            if (!string.IsNullOrEmpty(info.strListaCoduri))
            {
                if (info.strListaCoduri.Contains('-'))
                {
                    arrFields = Regex.Split(info.strListaCoduri, "-");
                    info.strListaCoduri = "";

                    if (Convert.ToInt32(arrFields[1]) < Convert.ToInt32(arrFields[0]))
                    {
                        message.Text = "<span class=\"redFont\">Range-ul nu este unul valid!</span>";
                        return;
                    }
                    for (int i = Convert.ToInt32(arrFields[0]); i <= Convert.ToInt32(arrFields[1]); ++i)
                    {
                        if (Convert.ToInt32(arrFields[1]) == i)
                            info.strListaCoduri += i.ToString();
                        else
                            info.strListaCoduri += i.ToString() + ",";
                    }
                }

                querystring += " AND RequestID IN (" + info.strListaCoduri + ")";
            }

            if (!string.IsNullOrEmpty(info.strSection))
            {
                querystring += "AND UPPER(SectionCode)=UPPER('" + info.strSection + "')";
            }

            if (!string.IsNullOrEmpty(info.strMedic))
            {
                // pacient case
                querystring += " AND (";
                querystring += "(ExternalType = 'PA' AND RequestorID=" + info.strMedic + ")";
                // presentation case
                querystring += " OR ((ExternalType = 'P' OR ExternalType = 'PR') AND EXISTS ";
                querystring += "(select * from vPresentationFull where ID=vRequestClass.ExternalID AND MedicID=" + info.strMedic + "))";
                // presentation case
                querystring += " OR (ExternalType = 'CI' AND EXISTS ";
                querystring += "(select * from vCheckInFull where CIID=vRequestClass.ExternalID AND CIMedicID=" + info.strMedic + "))";
                // checkup case
                querystring += " OR (ExternalType = 'CU' AND EXISTS ";
                querystring += "(select * from vCheckUpFull where CUID=vRequestClass.ExternalID AND CUMedic=" + info.strMedic + "))";
                // checkout case
                querystring += " OR (ExternalType = 'CO' AND EXISTS ";
                querystring += "(select * from vCheckOutFull where COID=vRequestClass.ExternalID AND COMedicID=" + info.strMedic + "))";
                querystring += ")";
            }

            if (!string.IsNullOrEmpty(info.strInvestigatie))
            {
                querystring += " AND UPPER(Class)=UPPER('" + info.strInvestigatie + "')";
            }

            if (info.startDate != null && info.endDate != null)
                querystring += " AND requestedDate BETWEEN '" + Tools.getSQLFormat_120(info.startDate) + "' AND '" + Tools.getSQLFormat_120(info.endDate) + "'";
            querystring += " order by RequestID ";

            DataSet dsRequest = Hipocrate.DB.DBConnection.GetData(querystring);
            DataView dvRequest = dsRequest.Tables[0].DefaultView;

            if (dvRequest.Count > 0)
            {
                for (int i = 0; i < dvRequest.Count; ++i)
                {
                    sortedData.Add(i, dvRequest[i]["RequestID"].ToString());
                }
            }

            SortedDictionary<int, string>.Enumerator sortedDic = sortedData.GetEnumerator();

            if (sortedData.Count > 0)
            {
                while (sortedDic.MoveNext())
                {
                    string queryDaterequest = "select *, convert(varchar(20), RequestedDate, 113) as strRequestedDate from LAB_REQUESTS where [id]=" + sortedDic.Current.Value;
                    DataSet dsDaterequest = Hipocrate.DB.DBConnection.GetData(queryDaterequest);
                    DataView dvDaterequest = dsDaterequest.Tables[0].DefaultView;

                    string querySection = "select [name] from sections where code='" + dvDaterequest[0]["SectionCode"].ToString() + "'";
                    DataSet dsSection = Hipocrate.DB.DBConnection.GetData(querySection);
                    DataView dvSection = dsSection.Tables[0].DefaultView;

                    string queryMedic = "";

                    if (!string.IsNullOrEmpty(dvDaterequest[0]["MedicID"].ToString()))
                    {
                        queryMedic += "select IsNull(LastName, '') + IsNull(' '+FirstName, '') as MedicFullName ";
                        queryMedic += "from staff where ID=" + dvDaterequest[0]["MedicID"].ToString();
                    }
                    else if (dvDaterequest[0]["ExternalType"].ToString() == "PA")
                    {
                        queryMedic += "";
                    }
                    else if (dvDaterequest[0]["ExternalType"].ToString() == "PR" || dvDaterequest[0]["ExternalType"].ToString() == "P")
                    {
                        queryMedic += "select MedicFullName from vPresentationFull where ID=" + dvDaterequest[0]["ExternalID"].ToString();
                    }
                    else if (dvDaterequest[0]["ExternalType"].ToString() == "CI")
                    {
                        queryMedic += "select MedicFullName from vCheckIn_LabRequests where CIID=" + dvDaterequest[0]["ExternalID"].ToString();
                    }
                    else if (dvDaterequest[0]["ExternalType"].ToString() == "CU")
                    {
                        queryMedic += "select MedicFullName from vCheckUpFull where CUID=" + dvDaterequest[0]["ExternalID"].ToString();
                    }
                    else if (dvDaterequest[0]["ExternalType"].ToString() == "CO")
                    {
                        queryMedic += "select MedicFullName from vCheckOutFull where COID=" + dvDaterequest[0]["ExternalID"].ToString();
                    }
                    else
                        queryMedic += "";

                    DataSet dsMedic = Hipocrate.DB.DBConnection.GetData(queryMedic);
                    DataView dvMedic = dsMedic.Tables[0].DefaultView;

                    string queryValidator = "select validatorID from LAB_SECTIONS where requestID=" + sortedDic.Current.Value + " AND SectionCode='" + dvDaterequest[0]["SectionCode"].ToString() + "'";
                    DataSet dsValidator = Hipocrate.DB.DBConnection.GetData(queryValidator);
                    DataView dvValidator = dsValidator.Tables[0].DefaultView;
                    if (dvValidator.Count == 0)
                    {
                        queryValidator = "select validatorID from LAB_SECTIONS where requestID=" + sortedDic.Current.Value;
                        dsValidator = Hipocrate.DB.DBConnection.GetData(queryValidator);
                        dvValidator = dsValidator.Tables[0].DefaultView;
                    }

                    string queryPacientData = "select *, DATEDIFF(yy, BirthDate, GetDate()) AS Age from vPacientFull where ID=" + dvDaterequest[0]["PacientID"].ToString();
                    DataSet dsPacientData = Hipocrate.DB.DBConnection.GetData(queryPacientData);
                    DataView dvPacientData = dsPacientData.Tables[0].DefaultView;

                    sb.Append("<table width=\"100%\" border=\"0\">");
                    sb.Append("<tr>");
                    sb.Append("<td valign=top align=\"left\" valign=\"top\">");
                    sb.Append("<span class=\"H3\">Spitalul Clinic de Urgenta pentru Copii 'GRIGORE ALEXANDRESCU'</span>");
                    sb.Append("</td>");
                    sb.Append("<td valign=top align=\"right\" valign=\"top\">");
                    sb.Append(siglaRSC());
                    sb.Append("</td>");
                    sb.Append("</tr>");
                    sb.Append("</table>");

                    sb.Append("<table width=\"100%\" border=\"0\">");
                    sb.Append("<tr>");
                    sb.Append("<td valign=top align=\"left\" valign=\"top\">");
                    sb.Append("<span class=\"H1\">BULETIN DE INVESTIGATII</span><br><br>");
                    sb.Append("<span class=\"H2\" style=\"width: 100px\">Cod buletin : </span>");
                    sb.Append("<span class=\"H2\" style=\"width: 100px\"> " + sortedDic.Current.Value + " </span><br>");
                    sb.Append("<span class=\"H2\" style=\"width: 100px\">Din data : </span>");
                    sb.Append("<span class=\"H2\" style=\"width: 170px\"> " + DateTime.Now.ToString() + " </span><br>");
                    sb.Append("</td>");

                    sb.Append("<td align=\"right\" valign=\"top\">");

                    sb.Append("<table width=\"350\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\" class=\"box1px\">");
                    sb.Append("<tr class=\"tdh\">");
                    sb.Append("<td valign=top align=\"left\" nowrap>Data cererii:</td>");
                    sb.Append("<td valign=top align=\"left\" nowrap>" + (dvSection.Count > 0 ? dvDaterequest[0]["strRequestedDate"].ToString() : "NECUNOSCUT") + "</td>");
                    sb.Append("<td valign=top rowspan=\"4\" align=\"right\" valign=\"top\" width=\"10%\">");
                    sb.Append("<span class=\"barCode\">" + sortedDic.Current.Value + "</span>");
                    sb.Append("</td>");
                    sb.Append("</tr>");
                    sb.Append("<tr class=\"tdh\">");
                    sb.Append("<td valign=top align=\"left\" nowrap>Sectia : </td>");
                    sb.Append("<td valign=top align=\"left\"> " + (dvSection.Count > 0 ? dvSection[0]["name"].ToString() : "NECUNOSCUT") + " </td>");
                    sb.Append("</tr>");
                    sb.Append("<tr class=\"tdh\">");
                    sb.Append("<td valign=top align=\"left\" nowrap>Ceruta de : </td>");
                    sb.Append("<td valign=top align=\"left\"> " + (dvMedic.Count > 0 ? dvMedic[0]["MedicFullName"].ToString() : "NECUNOSCUT") + " </td>");
                    sb.Append("</tr>");
                    sb.Append("<tr class=\"tdh\">");
                    sb.Append("<td valign=top align=\"left\" nowrap>Medic : </td>");
                    sb.Append("<td valign=top align=\"left\"> " + (dvValidator.Count > 0 ? dvValidator[0]["validatorID"].ToString() : "NECUNOSCUT") + " </td>");
                    sb.Append("</tr>");
                    sb.Append("</table>");

                    sb.Append("<table  border=\"0\">");
                    sb.Append("<td valign=top>Urgenta</td>");
                    sb.Append("<td valign=top class=\"tdn\">&nbsp; <b> " + (dvDaterequest[0]["Priority"].ToString() == "0" ? "DA" : "NU") + " </b> &nbsp;</td>");
                    sb.Append("</table>");

                    sb.Append("</td>");
                    sb.Append("</tr>");
                    sb.Append("</table>");

                    sb.Append("<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"1\" style=\"padding-top: 10px\">");
                    sb.Append("<tr class=\"tdh\">");
                    sb.Append("<td valign=top>COD</td>");
                    sb.Append("<td valign=top>Nume</td>");
                    sb.Append("<td valign=top width=\"1%\">Sex</td>");
                    sb.Append("<td valign=top width=\"1%\">Varsta</td>");
                    sb.Append("<td valign=top>CNP</td>");
                    sb.Append("</tr>");
                    sb.Append("<tr>");
                    sb.Append("<td valign=top class=\"tdnplus\"> " + (dvDaterequest[0]["PacientID"] != System.DBNull.Value ? dvDaterequest[0]["PacientID"].ToString() : "") + " </td>");
                    sb.Append("<td valign=top class=\"tdnplus\"><span class=\"H1\"> " + (dvPacientData.Count > 0 ? dvPacientData[0]["LastName"].ToString() + " " + dvPacientData[0]["FirstName"].ToString() : "") + " </span></td>");
                    sb.Append("<td valign=top class=\"tdnplus\"> " + (dvPacientData[0]["Sex"] != System.DBNull.Value ? (dvPacientData[0]["sex"].ToString() == "0" ? "F" : "M") : "") + " </td>");
                    sb.Append("<td valign=top class=\"tdnplus\"> " + (dvPacientData[0]["age"] != System.DBNull.Value ? dvPacientData[0]["age"].ToString() : "") + " </td>");
                    sb.Append("<td valign=top class=\"tdnplus\"> " + (dvPacientData[0]["CNP"] != System.DBNull.Value ? dvPacientData[0]["CNP"].ToString() : "") + " </td>");
                    sb.Append("</tr>");
                    sb.Append("</table>");

                    sb.Append("<br/>");

                    string queryAnalyse = "select distinct class from vAnalyseReport_List where RequestID=" + sortedDic.Current.Value;
                    DataSet dsAnalyse = Hipocrate.DB.DBConnection.GetData(queryAnalyse);
                    DataView dvAnalyse = dsAnalyse.Tables[0].DefaultView;

                    for (int i = 0; i < dvAnalyse.Count; ++i)
                    {
                        sb.Append("<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" >");
                        sb.Append("<tr>");
                        sb.Append("<td valign=top class=\"tdnplusleft\" colspan=\"4\" > " + dvAnalyse[i]["class"].ToString() + " </td>");
                        sb.Append("</tr>");

                        string queryRefAnalyse = "select * from vAnalyseReport_List where RequestID=" + sortedDic.Current.Value;
                        queryRefAnalyse += " AND UPPER(Class)=UPPER('" + dvAnalyse[i]["class"].ToString() + "')";
                        DataSet dsRefAnalyse = Hipocrate.DB.DBConnection.GetData(queryRefAnalyse);
                        DataView dvRefAnalyse = dsRefAnalyse.Tables[0].DefaultView;

                        for (int j = 0; j < dvRefAnalyse.Count; ++j)
                        {
                            string queryRefResults = "select *, convert(varchar(20), resDate, 113) as resDate from vAnalyseResults where ID=" + dvRefAnalyse[j]["AnalyseID"].ToString();
                            DataSet dsRefResults = Hipocrate.DB.DBConnection.GetData(queryRefResults, false);
                            DataView dvRefResults = dsRefResults.Tables[0].DefaultView;

                            if (dvRefResults.Count == 1)
                            {
                                sb.Append("<tr>");
                                sb.Append("<td valign=top class=\"tdnBlock\" width=\"30%\"> <b>" + dvRefAnalyse[j]["AnalyseName"].ToString() + "</b> </td>");
                                sb.Append("<td valign=top class=\"tdn\" width=\"20%\"> " + dvRefResults[0]["StringValue"].ToString() + " </td>");
                                sb.Append("<td valign=top class=\"tdn\" width=\"20%\"> " + dvRefResults[0]["UMName"].ToString() + " </td>");
                                sb.Append("<td valign=top class=\"tdnright\" width=\"30%\"> " + dvDaterequest[0]["strRequestedDate"].ToString() + " </td>");
                                sb.Append("</tr>");
                            }
                            else if (dvRefResults.Count > 1)
                            {
                                sb.Append("<tr>");
                                sb.Append("<td valign=top class=\"tdnBlock\" width=\"70%\"> <b>" + dvRefAnalyse[j]["AnalyseName"].ToString() + "</b> </td>");
                                sb.Append("<td valign=top class=\"tdnright\" width=\"30%\" colspan=\"3\">" + dvDaterequest[0]["strRequestedDate"].ToString() + "</td>");
                                sb.Append("</tr>");

                                sb.Append("<tr>");
                                sb.Append("<td valign=top class='tdright' colspan='6'>");
                                sb.Append("<table class='tdn' border='0' cellspacing='0' cellpadding='0'>");

                                for (int k = 0; k < dvRefResults.Count; ++k)
                                {
                                    sb.Append("<tr>");
                                    sb.Append("<td class='tdright'>");
                                    sb.Append("<b><span class='greenFont'>" + dvRefResults[k]["Name"].ToString() + "</span></b>&nbsp;");
                                    sb.Append("</td>");
                                    sb.Append("<td class='tdn'>");
                                    sb.Append("<table width='100%' border='0' cellpadding='0' cellspacing='0'>");
                                    sb.Append("<tr>");
                                    sb.Append("<td class='tdn_ok'>");
                                    sb.Append("&nbsp;<span class='redFont'>" + dvRefResults[k]["StringValue"].ToString() + "</span>");
                                    sb.Append("</td>");
                                    sb.Append("</tr>");
                                    sb.Append("</table>");
                                    sb.Append("</td>");
                                    sb.Append("<td class='tdleft'>");
                                    sb.Append("<small>&nbsp;<span class='blueFont'>" + dvRefResults[k]["UMName"].ToString().Replace("[", "<").Replace("]", ">") + "</span></small>&nbsp;");
                                    sb.Append("</td>");
                                    sb.Append("</tr>");
                                }

                                sb.Append("</table>");
                                sb.Append("</td>");
                                sb.Append("</tr>");

                            }
                            else if (dvRefResults.Count == 0)
                            {
                                sb.Append("<tr>");
                                sb.Append("<td valign=top class=\"tdnBlock\" width=\"50%\"> <b>" + dvRefAnalyse[j]["AnalyseName"].ToString() + "</b> </td>");
                                sb.Append("<td valign=top class=\"tdnright\" width=\"50%\" colspan=\"3\"><span>Investigatia nu este procesata.</span></td>");
                                sb.Append("</tr>");
                            }
                        }

                        sb.Append("</table>");
                    }

                    sb.Append("<br/><br/>");
                    sb.Append("<span class=\"redFont\"><center>~~~</center></span>");
                }
            }
            else
            {
                sb.Append("<table width=\"100%\" border=\"0\">");
                sb.Append("<tr>");
                sb.Append("<td valign=top align=\"left\" valign=\"top\">");
                sb.Append("<span class=\"H3\">Spitalul Clinic de Urgenta pentru Copii 'GRIGORE ALEXANDRESCU'</span>");
                sb.Append("</td>");
                sb.Append("<td valign=top align=\"right\" valign=\"top\">");
                sb.Append("<a href=\"..\\ReportsLaboratory.aspx\">sistem informatic HIPOCRATE<br/>@RSC<br/>E-mail: office@rsc.ro</span></a>");
                sb.Append("</td>");
                sb.Append("</tr>");
                sb.Append("</table>");

                sb.Append("<span class=\"redFont\">Nici o cerere nu a fost gasita conform criteriilor de cautare selectate.</span>");
            }

            phCommonReport.Controls.Add(new LiteralControl(sb.ToString()));
        }
        catch (Exception ex)
        {
            message.Text = ex.ToString();
        }
    }

    protected void ImprimareRegistruCercetare(CommonSession.StareRapoarteLaborator info)
    {
        try
        {
            SortedDictionary<int, string> sortedData = new SortedDictionary<int, string>();
            string querystring = "select distinct RequestID from vRequestClass where 1=1 ";
            querystring += " AND UPPER(Class)=UPPER('" + info.groupByTypes + "')";

            if (info.startDate != null && info.endDate != null)
                querystring += " AND requestedDate BETWEEN '" + Tools.getSQLFormat_120(info.startDate) + "' AND '" + Tools.getSQLFormat_120(info.endDate) + "'";

            if (info.bTehnice == false)
                querystring += " and Test <> 1 ";

            if (!string.IsNullOrEmpty(info.strInvestigatie))
            {
                if (!string.IsNullOrEmpty(info.comparedValue1) && string.IsNullOrEmpty(info.comparedValue2))
                {
                    if (info.comparerOp1 == "<" || info.comparerOp1 == ">")
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID) where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' ";
                        querystring += " AND  (  REFS.ValueType='INT'  AND IsNumeric(RESULTS.StringValue)=1 AND LTRIM(RTRIM(RESULTS.StringValue)) NOT IN ('-', '+', '.', ',')  AND IsNumeric('" + info.comparedValue1 + "')=1  AND CAST(RESULTS.StringValue as FLOAT) " + info.comparerOp1 + " CAST('" + info.comparedValue1 + "' as FLOAT)  ) )";
                    }
                    else if (info.comparerOp1 == "=")
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID) where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' ";
                        querystring += " AND  RESULTS.StringValue = '" + info.comparedValue1 + "')";
                    }
                    else if (info.comparerOp1 == "%")
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID) where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' ";
                        querystring += " AND  RESULTS.StringValue LIKE '" + info.comparedValue1 + "')";
                    }
                }
                else if (!string.IsNullOrEmpty(info.comparedValue2) && string.IsNullOrEmpty(info.comparedValue1))
                {
                    if (info.comparerOp2 == "<" || info.comparerOp2 == ">")
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID) where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' ";
                        querystring += " AND  (  REFS.ValueType='INT'  AND IsNumeric(RESULTS.StringValue)=1 AND LTRIM(RTRIM(RESULTS.StringValue)) NOT IN ('-', '+', '.', ',')  AND IsNumeric('" + info.comparedValue2 + "')=1  AND CAST(RESULTS.StringValue as FLOAT) " + info.comparerOp2 + " CAST('" + info.comparedValue2 + "' as FLOAT)  ) )";
                    }
                    else if (info.comparerOp2 == "=")
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID) where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' ";
                        querystring += " AND  RESULTS.StringValue = '" + info.comparedValue2 + "')";
                    }
                    else if (info.comparerOp2 == "%")
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID) where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' ";
                        querystring += " AND  RESULTS.StringValue LIKE '" + info.comparedValue2 + "')";
                    }
                }
                else if (!string.IsNullOrEmpty(info.comparedValue1) && !string.IsNullOrEmpty(info.comparedValue2))
                {
                    if ((info.comparerOp1 == "<" || info.comparerOp1 == ">") && (info.comparerOp2 == "<" || info.comparerOp2 == ">"))
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID)  where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] ='" + info.strInvestigatie + "' ";
                        querystring += " AND  (  (  (  REFS.ValueType='INT'  AND IsNumeric(RESULTS.StringValue)=1 AND LTRIM(RTRIM(RESULTS.StringValue)) NOT IN ('-', '+', '.', ',')  AND IsNumeric('" + info.comparedValue1 + "')=1  AND CAST(RESULTS.StringValue as FLOAT) " + info.comparerOp1 + " CAST('" + info.comparedValue1 + "' as FLOAT)  )  ) ";
                        querystring += info.compareType;
                        querystring += " (  (  REFS.ValueType='INT'  AND IsNumeric(RESULTS.StringValue)=1 AND LTRIM(RTRIM(RESULTS.StringValue)) NOT IN ('-', '+', '.', ',')  AND IsNumeric('" + info.comparedValue2 + "')=1  AND CAST(RESULTS.StringValue as FLOAT) " + info.comparerOp2 + " CAST('" + info.comparedValue2 + "' as FLOAT)  )  )  ) ) ";
                    }
                    else if (info.comparerOp1 == "=" && info.comparerOp2 == "=")
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID)  where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' ";
                        querystring += " AND  (  (  RESULTS.StringValue = '" + info.comparedValue1 + "'  )";
                        querystring += info.compareType;
                        querystring += " (  RESULTS.StringValue = '" + info.comparedValue2 + "'  )  ) ) ";
                    }
                    else if (info.comparerOp1 == "%" && info.comparerOp2 == "%")
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID)  where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' ";
                        querystring += " AND  (  (  RESULTS.StringValue LIKE '" + info.comparedValue1 + "'  ) ";
                        querystring += info.compareType;
                        querystring += " (  RESULTS.StringValue LIKE '" + info.comparedValue2 + "'  )  ) ) ";
                    }
                    else if ((info.comparerOp1 == "<" || info.comparerOp1 == ">") && (info.comparerOp2 == "="))
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID)  where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' ";
                        querystring += " AND  (  (  (  REFS.ValueType='INT'  AND IsNumeric(RESULTS.StringValue)=1 AND LTRIM(RTRIM(RESULTS.StringValue)) NOT IN ('-', '+', '.', ',')  AND IsNumeric('" + info.comparedValue1 + "')=1  AND CAST(RESULTS.StringValue as FLOAT) " + info.comparerOp1 + " CAST('" + info.comparedValue1 + "' as FLOAT)  )  )";
                        querystring += info.compareType;
                        querystring += " (  RESULTS.StringValue = '" + info.comparedValue2 + "'  )  ) ) ";
                    }
                    else if ((info.comparerOp1 == "=") && (info.comparerOp2 == "<" || info.comparerOp2 == ">"))
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID)  where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' ";
                        querystring += " AND  (  (  RESULTS.StringValue = '" + info.comparedValue1 + "'  ) ";
                        querystring += info.compareType;
                        querystring += " (  (  REFS.ValueType='INT'  AND IsNumeric(RESULTS.StringValue)=1 AND LTRIM(RTRIM(RESULTS.StringValue)) NOT IN ('-', '+', '.', ',')  AND IsNumeric('" + info.comparedValue2 + "')=1  AND CAST(RESULTS.StringValue as FLOAT) " + info.comparerOp2 + " CAST('" + info.comparedValue2 + "' as FLOAT)  )  )  ) )";
                    }
                    else if ((info.comparerOp1 == "<" || info.comparerOp1 == ">") && (info.comparerOp2 == "%"))
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID)  where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' ";
                        querystring += " AND  (  (  (  REFS.ValueType='INT'  AND IsNumeric(RESULTS.StringValue)=1 AND LTRIM(RTRIM(RESULTS.StringValue)) NOT IN ('-', '+', '.', ',')  AND IsNumeric('" + info.comparedValue1 + "')=1  AND CAST(RESULTS.StringValue as FLOAT) " + info.comparerOp1 + " CAST('" + info.comparedValue1 + "' as FLOAT)  )  )";
                        querystring += info.compareType;
                        querystring += " (  RESULTS.StringValue LIKE '" + info.comparedValue2 + "'  )  ) ) ";
                    }
                    else if ((info.comparerOp1 == "%") && (info.comparerOp2 == "<" || info.comparerOp2 == ">"))
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID)  where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' ";
                        querystring += " AND  (  (  RESULTS.StringValue LIKE '" + info.comparedValue1 + "'  ) ";
                        querystring += info.compareType;
                        querystring += "  (  (  REFS.ValueType='INT'  AND IsNumeric(RESULTS.StringValue)=1 AND LTRIM(RTRIM(RESULTS.StringValue)) NOT IN ('-', '+', '.', ',')  AND IsNumeric('" + info.comparedValue2 + "')=1  AND CAST(RESULTS.StringValue as FLOAT) " + info.comparerOp1 + " CAST('" + info.comparedValue2 + "' as FLOAT)  )  )  ) )";
                    }
                    else if ((info.comparerOp1 == "=") && (info.comparerOp2 == "%"))
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID)  where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' ";
                        querystring += " AND  (  (  RESULTS.StringValue = '" + info.comparedValue1 + "'  ) ";
                        querystring += info.compareType;
                        querystring += " (  RESULTS.StringValue LIKE '" + info.comparedValue2 + "'  )  ) ) ";
                    }
                    else if ((info.comparerOp1 == "%") && (info.comparerOp2 == "="))
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID)  where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' ";
                        querystring += " AND  (  (  RESULTS.StringValue LIKE '" + info.comparedValue1 + "'  ) ";
                        querystring += info.compareType;
                        querystring += " (  RESULTS.StringValue = '" + info.comparedValue2 + "'  )  ) ) ";
                    }
                }
                else
                    querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  where A.RequestID=vRequestClass.RequestID AND A_T.[Name] = '" + info.strInvestigatie + "' ) ";

            }
            else if (!string.IsNullOrEmpty(info.strRezultat))
            {
                if (!string.IsNullOrEmpty(info.comparedValue1) && string.IsNullOrEmpty(info.comparedValue2))
                {
                    if (info.comparerOp1 == "<" || info.comparerOp1 == ">")
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID) where A.RequestID=vRequestClass.RequestID  AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  (  REFS.ValueType='INT'  AND IsNumeric(RESULTS.StringValue)=1 AND LTRIM(RTRIM(RESULTS.StringValue)) NOT IN ('-', '+', '.', ',')  AND IsNumeric('" + info.comparedValue1 + "')=1  AND CAST(RESULTS.StringValue as FLOAT) " + info.comparerOp1 + " CAST('" + info.comparedValue1 + "' as FLOAT)  ) )";
                    }
                    else if (info.comparerOp1 == "=")
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID) where A.RequestID=vRequestClass.RequestID  AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  RESULTS.StringValue = '" + info.comparedValue1 + "')";
                    }
                    else if (info.comparerOp1 == "%")
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID) where A.RequestID=vRequestClass.RequestID  AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  RESULTS.StringValue LIKE '" + info.comparedValue1 + "')";
                    }
                }
                else if (!string.IsNullOrEmpty(info.comparedValue2) && string.IsNullOrEmpty(info.comparedValue1))
                {
                    if (info.comparerOp2 == "<" || info.comparerOp2 == ">")
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID) where A.RequestID=vRequestClass.RequestID  AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  (  REFS.ValueType='INT'  AND IsNumeric(RESULTS.StringValue)=1 AND LTRIM(RTRIM(RESULTS.StringValue)) NOT IN ('-', '+', '.', ',')  AND IsNumeric('" + info.comparedValue2 + "')=1  AND CAST(RESULTS.StringValue as FLOAT) " + info.comparerOp2 + " CAST('" + info.comparedValue2 + "' as FLOAT)  ) )";
                    }
                    else if (info.comparerOp2 == "=")
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID) where A.RequestID=vRequestClass.RequestID  AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  RESULTS.StringValue = '" + info.comparedValue2 + "')";
                    }
                    else if (info.comparerOp2 == "%")
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID) where A.RequestID=vRequestClass.RequestID  AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  RESULTS.StringValue LIKE '" + info.comparedValue2 + "')";
                    }
                }
                else if (!string.IsNullOrEmpty(info.comparedValue1) && !string.IsNullOrEmpty(info.comparedValue2))
                {
                    if ((info.comparerOp1 == "<" || info.comparerOp1 == ">") && (info.comparerOp2 == "<" || info.comparerOp2 == ">"))
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID)  where A.RequestID=vRequestClass.RequestID  AND REFS.[Name] ='" + info.strRezultat + "' ";
                        querystring += " AND  (  (  (  REFS.ValueType='INT'  AND IsNumeric(RESULTS.StringValue)=1 AND LTRIM(RTRIM(RESULTS.StringValue)) NOT IN ('-', '+', '.', ',')  AND IsNumeric('" + info.comparedValue1 + "')=1  AND CAST(RESULTS.StringValue as FLOAT) " + info.comparerOp1 + " CAST('" + info.comparedValue1 + "' as FLOAT)  )  ) ";
                        querystring += info.compareType;
                        querystring += " (  (  REFS.ValueType='INT'  AND IsNumeric(RESULTS.StringValue)=1 AND LTRIM(RTRIM(RESULTS.StringValue)) NOT IN ('-', '+', '.', ',')  AND IsNumeric('" + info.comparedValue2 + "')=1  AND CAST(RESULTS.StringValue as FLOAT) " + info.comparerOp2 + " CAST('" + info.comparedValue2 + "' as FLOAT)  )  )  ) ) ";
                    }
                    else if (info.comparerOp1 == "=" && info.comparerOp2 == "=")
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID)  where A.RequestID=vRequestClass.RequestID  AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  (  (  RESULTS.StringValue = '" + info.comparedValue1 + "'  )";
                        querystring += info.compareType;
                        querystring += " (  RESULTS.StringValue = '" + info.comparedValue2 + "'  )  ) ) ";
                    }
                    else if (info.comparerOp1 == "%" && info.comparerOp2 == "%")
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID)  where A.RequestID=vRequestClass.RequestID  AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  (  (  RESULTS.StringValue LIKE '" + info.comparedValue1 + "'  ) ";
                        querystring += info.compareType;
                        querystring += " (  RESULTS.StringValue LIKE '" + info.comparedValue2 + "'  )  ) ) ";
                    }
                    else if ((info.comparerOp1 == "<" || info.comparerOp1 == ">") && (info.comparerOp2 == "="))
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID)  where A.RequestID=vRequestClass.RequestID  AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  (  (  (  REFS.ValueType='INT'  AND IsNumeric(RESULTS.StringValue)=1 AND LTRIM(RTRIM(RESULTS.StringValue)) NOT IN ('-', '+', '.', ',')  AND IsNumeric('" + info.comparedValue1 + "')=1  AND CAST(RESULTS.StringValue as FLOAT) " + info.comparerOp1 + " CAST('" + info.comparedValue1 + "' as FLOAT)  )  )";
                        querystring += info.compareType;
                        querystring += " (  RESULTS.StringValue = '" + info.comparedValue2 + "'  )  ) ) ";
                    }
                    else if ((info.comparerOp1 == "=") && (info.comparerOp2 == "<" || info.comparerOp2 == ">"))
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID)  where A.RequestID=vRequestClass.RequestID  AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  (  (  RESULTS.StringValue = '" + info.comparedValue1 + "'  ) ";
                        querystring += info.compareType;
                        querystring += " (  (  REFS.ValueType='INT'  AND IsNumeric(RESULTS.StringValue)=1 AND LTRIM(RTRIM(RESULTS.StringValue)) NOT IN ('-', '+', '.', ',')  AND IsNumeric('" + info.comparedValue2 + "')=1  AND CAST(RESULTS.StringValue as FLOAT) " + info.comparerOp2 + " CAST('" + info.comparedValue2 + "' as FLOAT)  )  )  ) )";
                    }
                    else if ((info.comparerOp1 == "<" || info.comparerOp1 == ">") && (info.comparerOp2 == "%"))
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID)  where A.RequestID=vRequestClass.RequestID  AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  (  (  (  REFS.ValueType='INT'  AND IsNumeric(RESULTS.StringValue)=1 AND LTRIM(RTRIM(RESULTS.StringValue)) NOT IN ('-', '+', '.', ',')  AND IsNumeric('" + info.comparedValue1 + "')=1  AND CAST(RESULTS.StringValue as FLOAT) " + info.comparerOp1 + " CAST('" + info.comparedValue1 + "' as FLOAT)  )  )";
                        querystring += info.compareType;
                        querystring += " (  RESULTS.StringValue LIKE '" + info.comparedValue2 + "'  )  ) ) ";
                    }
                    else if ((info.comparerOp1 == "%") && (info.comparerOp2 == "<" || info.comparerOp2 == ">"))
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID)  where A.RequestID=vRequestClass.RequestID  AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  (  (  RESULTS.StringValue LIKE '" + info.comparedValue1 + "'  ) ";
                        querystring += info.compareType;
                        querystring += "  (  (  REFS.ValueType='INT'  AND IsNumeric(RESULTS.StringValue)=1 AND LTRIM(RTRIM(RESULTS.StringValue)) NOT IN ('-', '+', '.', ',')  AND IsNumeric('" + info.comparedValue2 + "')=1  AND CAST(RESULTS.StringValue as FLOAT) " + info.comparerOp1 + " CAST('" + info.comparedValue2 + "' as FLOAT)  )  )  ) )";
                    }
                    else if ((info.comparerOp1 == "=") && (info.comparerOp2 == "%"))
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID)  where A.RequestID=vRequestClass.RequestID  AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  (  (  RESULTS.StringValue = '" + info.comparedValue1 + "'  ) ";
                        querystring += info.compareType;
                        querystring += " (  RESULTS.StringValue LIKE '" + info.comparedValue2 + "'  )  ) ) ";
                    }
                    else if ((info.comparerOp1 == "%") && (info.comparerOp2 == "="))
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID)  where A.RequestID=vRequestClass.RequestID  AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  (  (  RESULTS.StringValue LIKE '" + info.comparedValue1 + "'  ) ";
                        querystring += info.compareType;
                        querystring += " (  RESULTS.StringValue = '" + info.comparedValue2 + "'  )  ) ) ";
                    }
                }
                else
                    querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  where A.RequestID=vRequestClass.RequestID AND REFS.[Name] = '" + info.strRezultat + "' ) ";
            }
            else if (!string.IsNullOrEmpty(info.strInvestigatie) && !string.IsNullOrEmpty(info.strRezultat))
            {
                if (!string.IsNullOrEmpty(info.comparedValue1) && string.IsNullOrEmpty(info.comparedValue2))
                {
                    if (info.comparerOp1 == "<" || info.comparerOp1 == ">")
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID) where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  (  REFS.ValueType='INT'  AND IsNumeric(RESULTS.StringValue)=1 AND LTRIM(RTRIM(RESULTS.StringValue)) NOT IN ('-', '+', '.', ',')  AND IsNumeric('" + info.comparedValue1 + "')=1  AND CAST(RESULTS.StringValue as FLOAT) " + info.comparerOp1 + " CAST('" + info.comparedValue1 + "' as FLOAT)  ) )";
                    }
                    else if (info.comparerOp1 == "=")
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID) where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  RESULTS.StringValue = '" + info.comparedValue1 + "')";
                    }
                    else if (info.comparerOp1 == "%")
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID) where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  RESULTS.StringValue LIKE '" + info.comparedValue1 + "')";
                    }
                }
                else if (!string.IsNullOrEmpty(info.comparedValue2) && string.IsNullOrEmpty(info.comparedValue1))
                {
                    if (info.comparerOp2 == "<" || info.comparerOp2 == ">")
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID) where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  (  REFS.ValueType='INT'  AND IsNumeric(RESULTS.StringValue)=1 AND LTRIM(RTRIM(RESULTS.StringValue)) NOT IN ('-', '+', '.', ',')  AND IsNumeric('" + info.comparedValue2 + "')=1  AND CAST(RESULTS.StringValue as FLOAT) " + info.comparerOp2 + " CAST('" + info.comparedValue2 + "' as FLOAT)  ) )";
                    }
                    else if (info.comparerOp2 == "=")
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID) where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  RESULTS.StringValue = '" + info.comparedValue2 + "')";
                    }
                    else if (info.comparerOp2 == "%")
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID) where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  RESULTS.StringValue LIKE '" + info.comparedValue2 + "')";
                    }
                }
                else if (!string.IsNullOrEmpty(info.comparedValue1) && !string.IsNullOrEmpty(info.comparedValue2))
                {
                    if ((info.comparerOp1 == "<" || info.comparerOp1 == ">") && (info.comparerOp2 == "<" || info.comparerOp2 == ">"))
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID)  where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] ='" + info.strInvestigatie + "' AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  (  (  (  REFS.ValueType='INT'  AND IsNumeric(RESULTS.StringValue)=1 AND LTRIM(RTRIM(RESULTS.StringValue)) NOT IN ('-', '+', '.', ',')  AND IsNumeric('" + info.comparedValue1 + "')=1  AND CAST(RESULTS.StringValue as FLOAT) " + info.comparerOp1 + " CAST('" + info.comparedValue1 + "' as FLOAT)  )  ) ";
                        querystring += info.compareType;
                        querystring += " (  (  REFS.ValueType='INT'  AND IsNumeric(RESULTS.StringValue)=1 AND LTRIM(RTRIM(RESULTS.StringValue)) NOT IN ('-', '+', '.', ',')  AND IsNumeric('" + info.comparedValue2 + "')=1  AND CAST(RESULTS.StringValue as FLOAT) " + info.comparerOp2 + " CAST('" + info.comparedValue2 + "' as FLOAT)  )  )  ) ) ";
                    }
                    else if (info.comparerOp1 == "=" && info.comparerOp2 == "=")
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID)  where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  (  (  RESULTS.StringValue = '" + info.comparedValue1 + "'  )";
                        querystring += info.compareType;
                        querystring += " (  RESULTS.StringValue = '" + info.comparedValue2 + "'  )  ) ) ";
                    }
                    else if (info.comparerOp1 == "%" && info.comparerOp2 == "%")
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID)  where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  (  (  RESULTS.StringValue LIKE '" + info.comparedValue1 + "'  ) ";
                        querystring += info.compareType;
                        querystring += " (  RESULTS.StringValue LIKE '" + info.comparedValue2 + "'  )  ) ) ";
                    }
                    else if ((info.comparerOp1 == "<" || info.comparerOp1 == ">") && (info.comparerOp2 == "="))
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID)  where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  (  (  (  REFS.ValueType='INT'  AND IsNumeric(RESULTS.StringValue)=1 AND LTRIM(RTRIM(RESULTS.StringValue)) NOT IN ('-', '+', '.', ',')  AND IsNumeric('" + info.comparedValue1 + "')=1  AND CAST(RESULTS.StringValue as FLOAT) " + info.comparerOp1 + " CAST('" + info.comparedValue1 + "' as FLOAT)  )  )";
                        querystring += info.compareType;
                        querystring += " (  RESULTS.StringValue = '" + info.comparedValue2 + "'  )  ) ) ";
                    }
                    else if ((info.comparerOp1 == "=") && (info.comparerOp2 == "<" || info.comparerOp2 == ">"))
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID)  where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  (  (  RESULTS.StringValue = '" + info.comparedValue1 + "'  ) ";
                        querystring += info.compareType;
                        querystring += " (  (  REFS.ValueType='INT'  AND IsNumeric(RESULTS.StringValue)=1 AND LTRIM(RTRIM(RESULTS.StringValue)) NOT IN ('-', '+', '.', ',')  AND IsNumeric('" + info.comparedValue2 + "')=1  AND CAST(RESULTS.StringValue as FLOAT) " + info.comparerOp2 + " CAST('" + info.comparedValue2 + "' as FLOAT)  )  )  ) )";
                    }
                    else if ((info.comparerOp1 == "<" || info.comparerOp1 == ">") && (info.comparerOp2 == "%"))
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID)  where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  (  (  (  REFS.ValueType='INT'  AND IsNumeric(RESULTS.StringValue)=1 AND LTRIM(RTRIM(RESULTS.StringValue)) NOT IN ('-', '+', '.', ',')  AND IsNumeric('" + info.comparedValue1 + "')=1  AND CAST(RESULTS.StringValue as FLOAT) " + info.comparerOp1 + " CAST('" + info.comparedValue1 + "' as FLOAT)  )  )";
                        querystring += info.compareType;
                        querystring += " (  RESULTS.StringValue LIKE '" + info.comparedValue2 + "'  )  ) ) ";
                    }
                    else if ((info.comparerOp1 == "%") && (info.comparerOp2 == "<" || info.comparerOp2 == ">"))
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID)  where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  (  (  RESULTS.StringValue LIKE '" + info.comparedValue1 + "'  ) ";
                        querystring += info.compareType;
                        querystring += "  (  (  REFS.ValueType='INT'  AND IsNumeric(RESULTS.StringValue)=1 AND LTRIM(RTRIM(RESULTS.StringValue)) NOT IN ('-', '+', '.', ',')  AND IsNumeric('" + info.comparedValue2 + "')=1  AND CAST(RESULTS.StringValue as FLOAT) " + info.comparerOp1 + " CAST('" + info.comparedValue2 + "' as FLOAT)  )  )  ) )";
                    }
                    else if ((info.comparerOp1 == "=") && (info.comparerOp2 == "%"))
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID)  where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  (  (  RESULTS.StringValue = '" + info.comparedValue1 + "'  ) ";
                        querystring += info.compareType;
                        querystring += " (  RESULTS.StringValue LIKE '" + info.comparedValue2 + "'  )  ) ) ";
                    }
                    else if ((info.comparerOp1 == "%") && (info.comparerOp2 == "="))
                    {
                        querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  join RESULTS on (A.ID=RESULTS.AnalyseID AND RESULTS.RefID=REFS.ID)  where A.RequestID=vRequestClass.RequestID  AND A_T.[Name] = '" + info.strInvestigatie + "' AND REFS.[Name] = '" + info.strRezultat + "' ";
                        querystring += " AND  (  (  RESULTS.StringValue LIKE '" + info.comparedValue1 + "'  ) ";
                        querystring += info.compareType;
                        querystring += " (  RESULTS.StringValue = '" + info.comparedValue2 + "'  )  ) ) ";
                    }
                }
                else
                    querystring += " and EXISTS (select * from ANALYSES A join ANALYSE_TYPES A_T on A.TypeID=A_T.ID  join REFS on A_T.ID=REFS.TypeID  where A.RequestID=vRequestClass.RequestID AND A_T.[Name] = '" + info.strInvestigatie + "' AND REFS.[Name] = '" + info.strRezultat + "') ";

            }

            querystring += " order by RequestID ";

            DataSet dsRequest = Hipocrate.DB.DBConnection.GetData(querystring);
            DataView dvRequest = dsRequest.Tables[0].DefaultView;

            if (dvRequest.Count > 0)
            {
                for (int i = 0; i < dvRequest.Count; ++i)
                {
                    sortedData.Add(i, dvRequest[i]["RequestID"].ToString());
                }
            }

            phCommonReport.Controls.Add(new LiteralControl("<table width=\"100%\" border=\"0\">"));
            phCommonReport.Controls.Add(new LiteralControl("<tr>"));
            phCommonReport.Controls.Add(new LiteralControl("<td valign=top align=\"left\" valign=\"top\">"));
            phCommonReport.Controls.Add(new LiteralControl("<span class=\"H3\">Spitalul Clinic de Urgenta pentru Copii 'GRIGORE ALEXANDRESCU'</span>"));
            phCommonReport.Controls.Add(new LiteralControl("</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td valign=top align=\"right\" valign=\"top\">"));
            phCommonReport.Controls.Add(new LiteralControl(siglaRSC()));
            phCommonReport.Controls.Add(new LiteralControl("</td>"));
            phCommonReport.Controls.Add(new LiteralControl("</tr>"));
            phCommonReport.Controls.Add(new LiteralControl("<tr>"));
            phCommonReport.Controls.Add(new LiteralControl("<td align=\"center\" colspan=\"2\">"));
            phCommonReport.Controls.Add(new LiteralControl("<span class=\"H1\">REGISTRU CERCETARE - " + info.groupByTypes + "</span><br>"));
            phCommonReport.Controls.Add(new LiteralControl("<span class=\"H3\"> de la " + info.startDate + " pana la " + info.endDate + "</span><br>"));
            phCommonReport.Controls.Add(new LiteralControl("</td>"));
            phCommonReport.Controls.Add(new LiteralControl("</tr>"));
            phCommonReport.Controls.Add(new LiteralControl("</table>"));

            phCommonReport.Controls.Add(new LiteralControl("<table class='tdn' border='0' cellpadding='0' cellspacing='0' width=\"100%\">"));
            phCommonReport.Controls.Add(new LiteralControl("<tr class='tdh'>"));
            phCommonReport.Controls.Add(new LiteralControl("<td valign=top width='10%'>Cerere</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td valign=top width='25%'>DE LA</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td valign=top width='40%'>Pacient</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td valign=top width='5%'>S /V</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td valign=top width='10%'>CNP</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td valign=top width='10%'>Salon</td>"));
            phCommonReport.Controls.Add(new LiteralControl("</tr>"));

            SortedDictionary<int, string>.Enumerator sortedDic = sortedData.GetEnumerator();

            if (sortedData.Count > 0)
            {
                while (sortedDic.MoveNext())
                {
                    string queryDaterequest = "select *, convert(varchar(20), RequestedDate, 113) as strRequestedDate from LAB_REQUESTS where [id]=" + sortedDic.Current.Value;
                    DataSet dsDaterequest = Hipocrate.DB.DBConnection.GetData(queryDaterequest);
                    DataView dvDaterequest = dsDaterequest.Tables[0].DefaultView;

                    string queryMedic = "";

                    if (!string.IsNullOrEmpty(dvDaterequest[0]["MedicID"].ToString()))
                    {
                        queryMedic += "select IsNull(LastName, '') + IsNull(' '+FirstName, '') as MedicFullName ";
                        queryMedic += "from staff where ID=" + dvDaterequest[0]["MedicID"].ToString();
                    }
                    else if (dvDaterequest[0]["ExternalType"].ToString() == "PA")
                    {
                        queryMedic += "";
                    }
                    else if (dvDaterequest[0]["ExternalType"].ToString() == "PR" || dvDaterequest[0]["ExternalType"].ToString() == "P")
                    {
                        queryMedic += "select MedicFullName from vPresentationFull where ID=" + dvDaterequest[0]["ExternalID"].ToString();
                    }
                    else if (dvDaterequest[0]["ExternalType"].ToString() == "CI")
                    {
                        queryMedic += "select MedicFullName from vCheckIn_LabRequests where CIID=" + dvDaterequest[0]["ExternalID"].ToString();
                    }
                    else if (dvDaterequest[0]["ExternalType"].ToString() == "CU")
                    {
                        queryMedic += "select MedicFullName from vCheckUpFull where CUID=" + dvDaterequest[0]["ExternalID"].ToString();
                    }
                    else if (dvDaterequest[0]["ExternalType"].ToString() == "CO")
                    {
                        queryMedic += "select MedicFullName from vCheckOutFull where COID=" + dvDaterequest[0]["ExternalID"].ToString();
                    }
                    else
                        queryMedic += "";

                    DataSet dsMedic = Hipocrate.DB.DBConnection.GetData(queryMedic);
                    DataView dvMedic = dsMedic.Tables[0].DefaultView;

                    string querySection = "select [name] from sections where code='" + dvDaterequest[0]["SectionCode"].ToString() + "'";
                    DataSet dsSection = Hipocrate.DB.DBConnection.GetData(querySection);
                    DataView dvSection = dsSection.Tables[0].DefaultView;

                    string queryPacientData = "select *, DATEDIFF(yy, BirthDate, GetDate()) AS Age from vPacientFull where ID=" + dvDaterequest[0]["PacientID"].ToString();
                    DataSet dsPacientData = Hipocrate.DB.DBConnection.GetData(queryPacientData, false);
                    DataView dvPacientData = dsPacientData.Tables[0].DefaultView;

                    phCommonReport.Controls.Add(new LiteralControl("<tr class='tdh'>"));
                    phCommonReport.Controls.Add(new LiteralControl("<td valign='top' class='tdnplus' width='10%'>" + sortedDic.Current.Value + "</br>" + dvDaterequest[0]["strRequestedDate"].ToString() + "</td>"));
                    phCommonReport.Controls.Add(new LiteralControl("<td valign='top' class='tdnplus' width='25%'>" + (dvMedic.Count > 0 ? dvMedic[0]["MedicFullName"].ToString() : "NECUNOSCUT") + "</br> " + (dvSection.Count > 0 ? dvSection[0]["name"].ToString() : "NECUNOSCUT") + "</td>"));
                    phCommonReport.Controls.Add(new LiteralControl("<td valign='top' class='tdnplus' width='40%'>" + (dvPacientData.Count > 0 ? dvPacientData[0]["LastName"].ToString() + " " + dvPacientData[0]["FirstName"].ToString() : "") + "</br>" + dvDaterequest[0]["PacientID"].ToString() + "</td>"));
                    phCommonReport.Controls.Add(new LiteralControl("<td valign='top' class='tdnplus' width='5%'>" + (dvPacientData[0]["Sex"] != System.DBNull.Value ? (dvPacientData[0]["sex"].ToString() == "0" ? "F" : "M") : "") + "/" + (dvPacientData[0]["age"] != System.DBNull.Value ? dvPacientData[0]["age"].ToString() : "") + "</td>"));
                    phCommonReport.Controls.Add(new LiteralControl("<td valign='top' class='tdnplus' width='10%'>" + (dvPacientData[0]["CNP"] != System.DBNull.Value ? dvPacientData[0]["CNP"].ToString() : "") + "</td>"));
                    phCommonReport.Controls.Add(new LiteralControl("<td valign='top' class='tdnplus' width='10%'>&nbsp;</td>"));
                    phCommonReport.Controls.Add(new LiteralControl("</tr>"));

                    string queryAnalyse = "select * from vAnalyseReport_All where RequestID=" + sortedDic.Current.Value + " AND UPPER(Class)=UPPER('" + info.groupByTypes + "') order by Class, analyseName";
                    DataSet dsAnalyse = Hipocrate.DB.DBConnection.GetData(queryAnalyse, false);
                    DataView dvAnalyse = dsAnalyse.Tables[0].DefaultView;

                    for (int i = 0; i < dvAnalyse.Count; ++i)
                    {
                        string queryRefAnalyse = "select *, convert(varchar(20), resDate, 113) as resDate from vAnalyseResults where ID=" + dvAnalyse[i]["AnalyseID"].ToString();
                        DataSet dsRefAnalyse = Hipocrate.DB.DBConnection.GetData(queryRefAnalyse, false);
                        DataView dvRefAnalyse = dsRefAnalyse.Tables[0].DefaultView;

                        phCommonReport.Controls.Add(new LiteralControl("<tr>"));
                        phCommonReport.Controls.Add(new LiteralControl("<td valign='top' class='tdnBlock' width='10%'>&nbsp;</td>"));
                        phCommonReport.Controls.Add(new LiteralControl("<td valign='top' class='tdnBlock' width='25%' colspan='1'><b>" + dvAnalyse[i]["AnalyseName"].ToString() + "</b></td>"));


                        if (dvRefAnalyse.Count > 0)
                        {
                            phCommonReport.Controls.Add(new LiteralControl("<td valign='top' class='tdnBlock' width='40%' colspan='2'>"));
                            phCommonReport.Controls.Add(new LiteralControl("<table border='0' width='100%'>"));

                            for (int j = 0; j < dvRefAnalyse.Count; ++j)
                            {
                                phCommonReport.Controls.Add(new LiteralControl("<tr>"));
                                phCommonReport.Controls.Add(new LiteralControl("<td valign='top' class='tdnBlock'>"));
                                phCommonReport.Controls.Add(new LiteralControl("<b>" + (dvRefAnalyse.Count > 0 ? dvRefAnalyse[j]["Name"].ToString() : "") + ":</b>" + (dvRefAnalyse.Count > 0 ? dvRefAnalyse[j]["StringValue"].ToString() : "")));
                                phCommonReport.Controls.Add(new LiteralControl("</td>"));
                                phCommonReport.Controls.Add(new LiteralControl("</tr>"));
                            }

                            phCommonReport.Controls.Add(new LiteralControl("</table>"));

                            phCommonReport.Controls.Add(new LiteralControl("</td>"));
                            phCommonReport.Controls.Add(new LiteralControl("<td valign='top' class='tdnright' width='25%' colspan='2'>" + (dvRefAnalyse.Count > 0 ? dvRefAnalyse[0]["ResDate"].ToString() : "") + "</td>"));
                        }
                        else
                        {
                            phCommonReport.Controls.Add(new LiteralControl("<td valign='top' class='tdnBlock' width='40%' colspan='2'>&nbsp;</td>"));
                            phCommonReport.Controls.Add(new LiteralControl("<td valign='top' class='tdnright' width='25%' colspan='2'>Investigatia nu este procesata.</td>"));
                        }

                        phCommonReport.Controls.Add(new LiteralControl("</tr>"));
                    }
                }

                phCommonReport.Controls.Add(new LiteralControl("</table>"));
            }
            else
            {
                phCommonReport.Controls.Add(new LiteralControl("</table>"));
                phCommonReport.Controls.Add(new LiteralControl("<span class=\"redFont\">Nici o cerere nu a fost gasita conform criteriilor de cautare selectate.</span>"));
            }
        }
        catch (Exception ex)
        {
            message.Text = ex.ToString();
        }
    }

    protected void CentralizationSectionMedics(CommonSession.StareRapoarteLaborator info)
    {
        try
        {
            SortedDictionary<int, string> sortedData = new SortedDictionary<int, string>();

            string querystring = "select distinct [Domain] as Class from LAB_DOMAINS WHERE 1=1 ";

            if (!info.groupByTypes.Contains("Toate"))
            {
                querystring += " AND [Domain] = '" + info.groupByTypes + "'";
            }

            querystring += " order by [Domain]";

            DataSet dsRequest = Hipocrate.DB.DBConnection.GetData(querystring);
            DataView dvRequest = dsRequest.Tables[0].DefaultView;

            if (dvRequest.Count > 0)
            {
                for (int i = 0; i < dvRequest.Count; ++i)
                {
                    sortedData.Add(i, dvRequest[i]["Class"].ToString());
                }
            }

            SortedDictionary<int, string>.Enumerator sortedDic = sortedData.GetEnumerator();

            if (sortedData.Count > 0)
            {
                while (sortedDic.MoveNext())
                {
                    phCommonReport.Controls.Add(new LiteralControl("<table width=\"100%\" border=\"0\">"));
                    phCommonReport.Controls.Add(new LiteralControl("<tr>"));
                    phCommonReport.Controls.Add(new LiteralControl("<td valign=top align=\"left\" valign=\"top\">"));
                    phCommonReport.Controls.Add(new LiteralControl("<span class=\"H3\">Spitalul Clinic de Urgenta pentru Copii 'GRIGORE ALEXANDRESCU'</span>"));
                    phCommonReport.Controls.Add(new LiteralControl("</td>"));
                    phCommonReport.Controls.Add(new LiteralControl("<td valign=top align=\"right\" valign=\"top\">"));
                    phCommonReport.Controls.Add(new LiteralControl(siglaRSC()));
                    phCommonReport.Controls.Add(new LiteralControl("</td>"));
                    phCommonReport.Controls.Add(new LiteralControl("</tr>"));
                    phCommonReport.Controls.Add(new LiteralControl("<tr>"));
                    phCommonReport.Controls.Add(new LiteralControl("<td align=\"center\" colspan=\"2\">"));
                    phCommonReport.Controls.Add(new LiteralControl("<span class=\"H1\">CENTRALIZATOR - " + sortedDic.Current.Value + "</span><br>"));
                    phCommonReport.Controls.Add(new LiteralControl("<span class=\"H3\"> de la " + info.startDate + " pana la " + info.endDate + "</span><br>"));
                    phCommonReport.Controls.Add(new LiteralControl("</td>"));
                    phCommonReport.Controls.Add(new LiteralControl("</tr>"));
                    phCommonReport.Controls.Add(new LiteralControl("</table>"));

                    string querystringAnalyse = "";

                    if (info.bNumeCodCAS)
                    {
                        querystringAnalyse += "select AnalyseName, ' ' as AnalyseCode, ";
                        if (info.bShowRepeatCounts)
                            querystringAnalyse += " sum([Count]) ";
                        else
                            querystringAnalyse += " count(AnalyseName) ";
                        querystringAnalyse += " as NR from vRequestClass ";
                    }
                    else
                    {
                        querystringAnalyse += "select CASAnalyseName AS AnalyseName, CASAnalyseCode as AnalyseCode, ";
                        if (info.bShowRepeatCounts)
                            querystringAnalyse += "sum([Count])";
                        else
                            querystringAnalyse += "count(AnalyseName)";
                        querystringAnalyse += " as NR from vRequestClass ";
                    }

                    querystringAnalyse += " where Class='" + sortedDic.Current.Value + "' ";

                    if (!string.IsNullOrEmpty(info.strSection))
                        querystringAnalyse += "and SectionCode='" + info.strSection + "'";
                    if (info.bProcessed)
                        querystringAnalyse += " AND status > 0 ";
                    if (info.bTehnice)
                        querystringAnalyse += " AND test <> 1 ";
                    if (info.bSpecifiedPayType)
                        querystringAnalyse += " AND PaymentTypeID = " + info.strPayType;
                    if (!string.IsNullOrEmpty(info.strMedic))
                    {
                        // pacient case
                        querystringAnalyse += " AND (";
                        querystringAnalyse += "(ExternalType = 'PA' AND RequestorID=" + info.strMedic + " OR MedicID= " + info.strMedic + ")";
                        // presentation case
                        querystringAnalyse += " OR ((ExternalType = 'P' OR ExternalType = 'PR') AND EXISTS ";
                        querystringAnalyse += "(select * from vPresentationFull where ID=vRequestClass.ExternalID AND MedicID=" + info.strMedic + "))";
                        // presentation case
                        querystringAnalyse += " OR (ExternalType = 'CI' AND EXISTS ";
                        querystringAnalyse += "(select * from vCheckInFull where CIID=vRequestClass.ExternalID AND CIMedicID=" + info.strMedic + "))";
                        // checkup case
                        querystringAnalyse += " OR (ExternalType = 'CU' AND EXISTS ";
                        querystringAnalyse += "(select * from vCheckUpFull where CUID=vRequestClass.ExternalID AND CUMedic=" + info.strMedic + "))";
                        // checkout case
                        querystringAnalyse += " OR (ExternalType = 'CO' AND EXISTS ";
                        querystringAnalyse += "(select * from vCheckOutFull where COID=vRequestClass.ExternalID AND COMedicID=" + info.strMedic + "))";
                        querystringAnalyse += ")";
                    }
                    if (info.startDate != null && info.endDate != null)
                        querystringAnalyse += " AND ISNULL(finishDate, changedDate) between '" + Tools.getSQLFormat_120(info.startDate) + "' AND '" + Tools.getSQLFormat_120(info.endDate) + "'";

                    if (info.bNumeCodCAS)
                        querystringAnalyse += " group by AnalyseName, AnalyseCode";
                    else
                        querystringAnalyse += " group by CASAnalyseName, CASAnalyseCode";

                    phCommonReport.Controls.Add(new LiteralControl("</br>"));

                    phCommonReport.Controls.Add(new LiteralControl("<table border='1' cellpadding='0' cellspacing='0' width='100%'>"));
                    phCommonReport.Controls.Add(new LiteralControl("<tr>"));
                    phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplusleft' width='70%'>Nume"));
                    phCommonReport.Controls.Add(new LiteralControl("</td>"));
                    if (info.bNumeCodCAS)
                    {
                        phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplusleft' width='10%'>Cod"));
                        phCommonReport.Controls.Add(new LiteralControl("</td>"));
                    }
                    phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' width='10%'>Numar"));
                    phCommonReport.Controls.Add(new LiteralControl("</td>"));
                    phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' width='5%'>Cost"));
                    phCommonReport.Controls.Add(new LiteralControl("</td>"));
                    phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' width='5%'>Total (Lei)"));
                    phCommonReport.Controls.Add(new LiteralControl("</td>"));
                    phCommonReport.Controls.Add(new LiteralControl("</tr>"));

                    DataSet dsAnalyse = Hipocrate.DB.DBConnection.GetData(querystringAnalyse);
                    DataView dvAnalyse = dsAnalyse.Tables[0].DefaultView;
                    int totalNRCount = 0;
                    decimal totalCosts = 0;

                    if (dvAnalyse.Count > 0)
                    {
                        for (int i = 0; i < dvAnalyse.Count; ++i)
                        {
                            string querystringCountAnalyse = "select count(*) as NR from Analyse_Types where [Name]='" + dvAnalyse[i]["AnalyseName"] + "'";
                            DataSet dsCountAnalyse = Hipocrate.DB.DBConnection.GetData(querystringCountAnalyse);
                            DataView dvCountAnalyse = dsCountAnalyse.Tables[0].DefaultView;

                            string queryAnalyseID = "";

                            if (dvCountAnalyse.Count == 1)
                            {
                                queryAnalyseID = "select ID from Analyse_Types where [Name]='" + dvAnalyse[i]["AnalyseName"].ToString() + "'";
                            }
                            else if (dvCountAnalyse.Count > 1)
                            {
                                queryAnalyseID = "select top 1 ID from Analyse_Types where [Name]='" + dvAnalyse[i]["AnalyseName"].ToString() + "'";
                                queryAnalyseID += "and exists (select * from vAnalyseType_Costs where Analyse_Types.ID=vAnalyseType_Costs.ID";
                                if (!string.IsNullOrEmpty(String.Format("{0:yyyy-MM-dd HH:mm:ss}", info.startDate)))
                                    queryAnalyseID += "AND CONVERT(DATETIME, '" + Tools.getSQLFormat_120(info.endDate) + "', 103) between startDate AND ISNULL(endDate, CONVERT(DATETIME, '" + Tools.getSQLFormat_120(info.endDate) + "', 103)) ";
                                else
                                    queryAnalyseID += " AND (endDate IS NULL OR GetDate() between startDate AND endDate)";

                                queryAnalyseID += " AND PaymentTypeID=" + info.strPayType;
                                queryAnalyseID += " ORDER BY Active DESC, Refs DESC";
                            }

                            DataSet dsAnalyseID = Hipocrate.DB.DBConnection.GetData(queryAnalyseID);
                            DataView dvAnalyseID = dsAnalyseID.Tables[0].DefaultView;
                            string cost = "";

                            if (dvAnalyseID.Count > 0)
                            {
                                string queryAnalyseCost = "select SUM(ISNULL(Qty, 0)*ISNULL(Price, 0)) as analyseCost from vAnalyseType_Costs where ID=" + dvAnalyseID[0]["ID"].ToString();
                                if (!string.IsNullOrEmpty(String.Format("{0:yyyy-MM-dd HH:mm:ss}", info.startDate)))
                                    queryAnalyseCost += " AND CONVERT(DATETIME, '" + Tools.getSQLFormat_103(info.endDate) + "', 103) between startDate AND ISNULL(endDate, CONVERT(DATETIME, '" + Tools.getSQLFormat_103(info.endDate) + "', 103)) ";
                                else
                                    queryAnalyseCost += " AND (endDate IS NULL OR GetDate() between startDate AND endDate)";
                                queryAnalyseCost += " AND PaymentTypeID=" + info.strPayType;

                                DataSet dsAnalyseCost = Hipocrate.DB.DBConnection.GetData(queryAnalyseCost);
                                DataView dvAnalyseCost = dsAnalyseCost.Tables[0].DefaultView;

                                if (dvAnalyseCost.Count > 0)
                                    cost = dvAnalyseCost[0]["analyseCost"].ToString();
                            }

                            decimal tempCost = 0;
                            if (!string.IsNullOrEmpty(cost))
                                tempCost = Convert.ToDecimal(cost) * Convert.ToDecimal(dvCountAnalyse[0]["NR"]);

                            phCommonReport.Controls.Add(new LiteralControl("<tr>"));
                            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnleft' width='70%'>" + (dvAnalyse.Count > 0 ? dvAnalyse[i]["AnalyseName"].ToString() : "") + ""));
                            phCommonReport.Controls.Add(new LiteralControl("</td>"));
                            if (info.bNumeCodCAS)
                            {
                                phCommonReport.Controls.Add(new LiteralControl("<td class='tdnleft' width='10%'>Cod"));
                                phCommonReport.Controls.Add(new LiteralControl("</td>"));
                            }
                            phCommonReport.Controls.Add(new LiteralControl("<td class='tdn' width='10%'>" + (dvCountAnalyse.Count > 0 ? dvCountAnalyse[0]["NR"].ToString() : "")));
                            phCommonReport.Controls.Add(new LiteralControl("</td>"));
                            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnright' width='5%'>" + (!string.IsNullOrEmpty(cost) ? cost : "&nbsp;")));
                            phCommonReport.Controls.Add(new LiteralControl("</td>"));
                            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnright' width='5%'>" + tempCost.ToString()));
                            phCommonReport.Controls.Add(new LiteralControl("</td>"));
                            phCommonReport.Controls.Add(new LiteralControl("</tr>"));
                            totalNRCount += (dvCountAnalyse.Count > 0 ? Convert.ToInt32(dvCountAnalyse[0]["NR"]) : 0);
                            totalCosts += tempCost;
                        }
                    }

                    phCommonReport.Controls.Add(new LiteralControl("<tr>"));
                    phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplusleft' width='70%'>TOTAL:"));
                    phCommonReport.Controls.Add(new LiteralControl("</td>"));
                    phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' width='10%'>" + totalNRCount));
                    phCommonReport.Controls.Add(new LiteralControl("</td>"));
                    phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplusright' width='5%'>X"));
                    phCommonReport.Controls.Add(new LiteralControl("</td>"));
                    phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplusright' width='5%'>" + totalCosts));
                    phCommonReport.Controls.Add(new LiteralControl("</td>"));
                    phCommonReport.Controls.Add(new LiteralControl("</tr>"));

                    phCommonReport.Controls.Add(new LiteralControl("</table>"));
                    phCommonReport.Controls.Add(new LiteralControl("</br>"));
                }
            }
        }
        catch (Exception ex)
        {
            message.Text = ex.ToString();
        }
    }

    protected void regPrimiri(CommonSession.StareRapoarteLaborator info)
    {
        try
        {
            string querystring = @"select distinct lr.id as RequestID,p.LastName+' '+p.FirstName as PacientName,p.cnp,s.LastName+' '+s.FirstName as medicTrimitator, 
                                       medtype.COD as tipTrimitere,mt.class  from lab_requests lr  
                                       left join analyses a on a.requestid=lr.id  
                                       left join pacients p on p.id=lr.pacientid  
                                       left join staff s on s.id=lr.medicid  
                                       left join medic_types	medtype on s.Medictypeid=medtype.id  
                                       left join machines m on a.machineid=m.id  
                                       left join machine_types mt on mt.id=m.typeid  
                                       left join lab_domains ld on mt.class=ld.domain ";

            if (info.startDate != null && info.endDate != null)
                querystring += "where lr.RequestedDate between '" + Tools.getSQLFormat_120(info.startDate) + "' AND '" + Tools.getSQLFormat_120(info.endDate) + "' ";

            if (info.strPayType != "*")
                querystring += " and a.paymenttypeid in " + info.strPayType;

            querystring += " and lr.deletedid is null ";

            if (info.groupByTypes != "*")
                querystring += " AND [Class] in " + info.groupByTypes;

            if (info.strMedicType != "0")
                querystring += " and MedicTypeID=" + info.strMedicType;

            if (info.strSection != "*" && !string.IsNullOrEmpty(info.strSection))
                querystring += " and ld.Section in" + info.strSection;

            querystring += " order by RequestId,class";

            phCommonReport.Controls.Add(new LiteralControl("<table width=\"100%\" border=\"0\">"));
            phCommonReport.Controls.Add(new LiteralControl("<tr>"));
            phCommonReport.Controls.Add(new LiteralControl("<td valign=top align=\"left\" valign=\"top\">"));
            phCommonReport.Controls.Add(new LiteralControl("<span class=\"H3\">Spitalul Clinic de Urgenta pentru Copii 'GRIGORE ALEXANDRESCU'</span>"));
            phCommonReport.Controls.Add(new LiteralControl("</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td valign=top align=\"right\" valign=\"top\">"));
            phCommonReport.Controls.Add(new LiteralControl(siglaRSC()));
            phCommonReport.Controls.Add(new LiteralControl("</td>"));
            phCommonReport.Controls.Add(new LiteralControl("</tr>"));
            phCommonReport.Controls.Add(new LiteralControl("<tr>"));
            phCommonReport.Controls.Add(new LiteralControl("<td align=\"center\" colspan=\"2\">"));
            phCommonReport.Controls.Add(new LiteralControl("<span class=\"H1\">Registrul primiri in perioada:</span></br></br>"));
            phCommonReport.Controls.Add(new LiteralControl("<span class=\"H3\">" + info.startDate + " - " + info.endDate + "</span><br>"));
            phCommonReport.Controls.Add(new LiteralControl("</td>"));
            phCommonReport.Controls.Add(new LiteralControl("</tr>"));
            phCommonReport.Controls.Add(new LiteralControl("</table>"));

            phCommonReport.Controls.Add(new LiteralControl("<table border='1' cellpadding='0' cellspacing='0' width='100%' ID='Table2'>"));
            phCommonReport.Controls.Add(new LiteralControl("<thead style='display:table-header-group'>"));
            phCommonReport.Controls.Add(new LiteralControl("<tr>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' align='center' width='5%'>&nbsp;Nr.<br>Crt</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' align='center' width='10%'>&nbsp;Cod<br>Cerere</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' align='center' width='15%'>&nbsp;Nume pacient</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' align='center' width='10%'>&nbsp;CNP</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' align='center' width='15%'>&nbsp;Medic<br>trimitator</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' align='center' width='5%'>&nbsp;Tip<br>Medic</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' align='center' width='40%'>&nbsp;Clase<br>Investigatii"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' nowrap width='5%'>&nbsp;Semnatura Primire</td>"));
            phCommonReport.Controls.Add(new LiteralControl("</tr>"));
            phCommonReport.Controls.Add(new LiteralControl("</thead>"));
            phCommonReport.Controls.Add(new LiteralControl("<tbody>"));

            DataSet dsRequest = Hipocrate.DB.DBConnection.GetData(querystring.Replace("&nbsp;", " "));
            DataView dvRequest = dsRequest.Tables[0].DefaultView;

            List<string> resultConcat = new List<string>();

            if (dvRequest.Count > 0)
            {
                string prevID = "";
                int counter = 0;

                for (int i = 0; i < dvRequest.Count; ++i)
                {
                    if (dvRequest[i]["RequestID"].ToString() != prevID)
                    {
                        prevID = dvRequest[i]["RequestID"].ToString();
                        counter++;

                        dvRequest.RowFilter = "RequestID=" + dvRequest[i]["RequestID"].ToString();
                        for (int j = 0; j < dvRequest.Count; ++j)
                            resultConcat.Add(dvRequest[j]["class"].ToString());
                        dvRequest.RowFilter = "";

                        phCommonReport.Controls.Add(new LiteralControl("<tr>"));
                        phCommonReport.Controls.Add(new LiteralControl("<td width='5%'>" + counter.ToString() + "</td>"));
                        phCommonReport.Controls.Add(new LiteralControl("<td width='10%'>" + dvRequest[i]["RequestID"].ToString() + "</td>"));
                        phCommonReport.Controls.Add(new LiteralControl("<td width='15%'>" + (!string.IsNullOrEmpty(dvRequest[i]["PacientName"].ToString()) ? dvRequest[i]["PacientName"].ToString() : "&nbsp;") + "</td>"));
                        phCommonReport.Controls.Add(new LiteralControl("<td width='10%'>" + (!string.IsNullOrEmpty(dvRequest[i]["cnp"].ToString()) ? dvRequest[i]["cnp"].ToString() : "&nbsp;") + "</td>"));
                        phCommonReport.Controls.Add(new LiteralControl("<td width='15%'>" + (!string.IsNullOrEmpty(dvRequest[i]["medicTrimitator"].ToString()) ? dvRequest[i]["medicTrimitator"].ToString() : "&nbsp;") + "</td>"));
                        phCommonReport.Controls.Add(new LiteralControl("<td width='5%'>" + (!string.IsNullOrEmpty(dvRequest[i]["tipTrimitere"].ToString()) ? dvRequest[i]["tipTrimitere"].ToString() : "&nbsp;") + "</td>"));
                        phCommonReport.Controls.Add(new LiteralControl("<td width='40%'>" + resultConcat.Join(";") + "</td>"));
                        phCommonReport.Controls.Add(new LiteralControl("<td width='5%'>&nbsp;</td>"));
                        phCommonReport.Controls.Add(new LiteralControl("</tr>"));
                        resultConcat.Clear();
                    }
                }
            }

            phCommonReport.Controls.Add(new LiteralControl("</tbody>"));
            phCommonReport.Controls.Add(new LiteralControl("<tfoot style='display:table-footer-group'>"));
            phCommonReport.Controls.Add(new LiteralControl("<tr>"));
            phCommonReport.Controls.Add(new LiteralControl("<td colspan=8>&nbsp;</td>"));
            phCommonReport.Controls.Add(new LiteralControl("</tr>"));
            phCommonReport.Controls.Add(new LiteralControl("</tfoot>"));
            phCommonReport.Controls.Add(new LiteralControl("</table>"));

            phCommonReport.Controls.Add(new LiteralControl("</br></br></br>"));
            phCommonReport.Controls.Add(new LiteralControl("<table border='0' cellpadding='0' cellspacing='0' width='100%' ID='Table3'>"));
            phCommonReport.Controls.Add(new LiteralControl("<tr height='40'>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdleft' colspan='2'>Raspundem de realitatea si exactitatea datelor</td>"));
            phCommonReport.Controls.Add(new LiteralControl("</tr>"));
            phCommonReport.Controls.Add(new LiteralControl("<tr height='40'>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdleft'>Reprezentant legal al cabinetului</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdright'>Semnatura si parafa medicului</td>"));
            phCommonReport.Controls.Add(new LiteralControl("</tr>"));
            phCommonReport.Controls.Add(new LiteralControl("</table>"));

        }
        catch (Exception ex)
        {
            message.Text = ex.ToString();
        }
    }

    protected void regPrimiriInvListVarste(CommonSession.StareRapoarteLaborator info)
    {
        try
        {
            string querystring = @" select lr.sectioncode,mt.class,at.name,1 as [count],ISNULL(datediff(year,p.BirthDate,GetDate()),0) as Age,  
                         case  when p.sex=1 or p.sex=3 then 'M' else 'F' end as SEX,ISNULL(loc.LocalitateUrbanRural,'u') as tipLoc   from analyses a  
                         left join analyse_types at on a.typeid=at.id  
                         left join lab_requests lr on lr.id=a.requestid  
                         left join Machines m on a.machineid=m.id  
                         left join Machine_types mt on m.typeid=mt.id  
                         left join lab_domains ld on mt.class=ld.domain  
                         left join staff s on s.id=lr.medicid  
                         left join medic_types	medtype on s.Medictypeid=medtype.id  
                         left join pacients p on p.id=lr.pacientid  
                         left join drg_city loc on loc.id=p.zoneid ";

            if (info.startDate != null && info.endDate != null)
                querystring += "where lr.requesteddate between '" + Tools.getSQLFormat_120(info.startDate) + "' AND '" + Tools.getSQLFormat_120(info.endDate) + "' ";

            if (info.strPayType != "*")
                querystring += " and a.paymenttypeid in " + info.strPayType;

            querystring += " and lr.deletedid is null ";

            if (info.groupByTypes != "*")
                querystring += " AND [Class] in " + info.groupByTypes;

            if (info.strMedicType != "0")
                querystring += " and MedicTypeID=" + info.strMedicType;

            if (info.strSection != "*" && !string.IsNullOrEmpty(info.strSection))
                querystring += " and ld.Section in" + info.strSection;

            querystring += " order by mt.class,at.name ";

            phCommonReport.Controls.Add(new LiteralControl("<table width=\"100%\" border=\"0\">"));
            phCommonReport.Controls.Add(new LiteralControl("<tr>"));
            phCommonReport.Controls.Add(new LiteralControl("<td valign=top align=\"left\" valign=\"top\">"));
            phCommonReport.Controls.Add(new LiteralControl("<span class=\"H3\">Spitalul Clinic de Urgenta pentru Copii 'GRIGORE ALEXANDRESCU'</span>"));
            phCommonReport.Controls.Add(new LiteralControl("</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td valign=top align=\"right\" valign=\"top\">"));
            phCommonReport.Controls.Add(new LiteralControl(siglaRSC()));
            phCommonReport.Controls.Add(new LiteralControl("</td>"));
            phCommonReport.Controls.Add(new LiteralControl("</tr>"));
            phCommonReport.Controls.Add(new LiteralControl("<tr>"));
            phCommonReport.Controls.Add(new LiteralControl("<td align=\"center\" colspan=\"2\">"));
            phCommonReport.Controls.Add(new LiteralControl("<span class=\"H1\">Investigatii efectuate in perioada:</span><br>"));
            phCommonReport.Controls.Add(new LiteralControl("<span class=\"H3\">" + info.startDate + " - " + info.endDate + "</span><br></br>"));
            phCommonReport.Controls.Add(new LiteralControl("</td>"));
            phCommonReport.Controls.Add(new LiteralControl("</tr>"));
            phCommonReport.Controls.Add(new LiteralControl("</table>"));

            phCommonReport.Controls.Add(new LiteralControl("<table border='1' cellpadding='0' cellspacing='0' width='100%' ID='Table2'>"));
            phCommonReport.Controls.Add(new LiteralControl("<thead>"));
            phCommonReport.Controls.Add(new LiteralControl("<tr>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' rowspan='3' width='2%'>&nbsp;Nr.<br>Crt</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' rowspan='3' width='40%'>&nbsp;Nume investigatie</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' colspan='13'>Nr Investigatii</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<tr>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' colspan='6'>Categorii de varsta</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' colspan='2'>SEX</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' colspan='2'>DOMICILIU</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' colspan='2'>Sectia</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' rowspan='2'  width='10%'>&nbsp;Total</td>"));
            phCommonReport.Controls.Add(new LiteralControl("</tr>"));
            phCommonReport.Controls.Add(new LiteralControl("<tr>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' width='5%'>&nbsp;0 - 14</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' width='5%'>&nbsp;15 - 24</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' width='5%'>&nbsp;25 - 39</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' width='5%'>&nbsp;40 - 59</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' width='5%'>&nbsp;60 - 79</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' width='5%'>&nbsp;80 si peste</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' width='2%'>&nbsp;F</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' width='2%'>&nbsp;B</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' width='5%'>&nbsp;Urban</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' width='5%'>&nbsp;Rural</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' width='5%'>&nbsp;Orto.</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplus' width='5%'>&nbsp;Pulm.</td>"));
            phCommonReport.Controls.Add(new LiteralControl("</tr>"));
            phCommonReport.Controls.Add(new LiteralControl("</tr>"));
            phCommonReport.Controls.Add(new LiteralControl("</thead>"));
            phCommonReport.Controls.Add(new LiteralControl("<tbody>"));

            DataSet dsRequest = Hipocrate.DB.DBConnection.GetData(querystring.Replace("&nbsp;", " "));
            DataView dvRequest = dsRequest.Tables[0].DefaultView;
            int counter = 1;

            if (dvRequest.Count > 0)
            {
                string prevClass = "";
                string prevName = "";
                int age0_14 = 0;
                int age15_24 = 0;
                int age25_39 = 0;
                int age40_59 = 0;
                int age60_79 = 0;
                int age80 = 0;
                int cF = 0;
                int cM = 0;
                int cUrban = 0;
                int cRural = 0;
                int cTotal = 0;
                int cOrto = 0;
                int cPulm = 0;

                for (int i = 0; i < dvRequest.Count; ++i)
                {
                    if (dvRequest[i]["class"].ToString() != prevClass)
                    {
                        prevClass = dvRequest[i]["class"].ToString();

                        phCommonReport.Controls.Add(new LiteralControl("<tr>"));
                        phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplusleft' width='2%'>&nbsp;</td>"));
                        phCommonReport.Controls.Add(new LiteralControl("<td class='tdnplusleft' width='100%' colspan='14'>" + dvRequest[i]["class"].ToString() + "</td>"));

                        phCommonReport.Controls.Add(new LiteralControl("</tr>"));
                    }
                    else if (dvRequest[i]["name"].ToString() != prevName)
                    {
                        prevName = dvRequest[i]["name"].ToString();

                        dvRequest.RowFilter = "name='" + dvRequest[i]["name"].ToString() + "'";
                        for (int j = 0; j < dvRequest.Count; ++j)
                        {
                            if (dvRequest[j]["Age"] != System.DBNull.Value && Convert.ToInt32(dvRequest[j]["Age"]) < 15)
                                age0_14++;
                            else if (dvRequest[j]["Age"] != System.DBNull.Value && Convert.ToInt32(dvRequest[j]["Age"]) >= 15)
                                age15_24++;
                            else if (dvRequest[j]["Age"] != System.DBNull.Value && Convert.ToInt32(dvRequest[j]["Age"]) >= 25)
                                age25_39++;
                            else if (dvRequest[j]["Age"] != System.DBNull.Value && Convert.ToInt32(dvRequest[j]["Age"]) >= 40)
                                age40_59++;
                            else if (dvRequest[j]["Age"] != System.DBNull.Value && Convert.ToInt32(dvRequest[j]["Age"]) >= 60)
                                age60_79++;
                            else if (dvRequest[j]["Age"] != System.DBNull.Value && Convert.ToInt32(dvRequest[j]["Age"]) >= 80)
                                age80++;
                            if (dvRequest[j]["SEX"] != System.DBNull.Value && (dvRequest[j]["SEX"]).ToString().ToString() == "F")
                                cF++;
                            else if (dvRequest[j]["SEX"] != System.DBNull.Value && (dvRequest[j]["SEX"]).ToString().ToString() == "M")
                                cM++;
                            if (dvRequest[j]["tipLoc"] != System.DBNull.Value && (dvRequest[j]["tipLoc"]).ToString() == "r")
                                cRural++;
                            else if (dvRequest[j]["tipLoc"] != System.DBNull.Value && (dvRequest[j]["tipLoc"]).ToString() == "u")
                                cUrban++;
                            if (dvRequest[j]["count"] != System.DBNull.Value && (dvRequest[j]["count"]).ToString() == "1")
                                cTotal++;
                            if (dvRequest[j]["sectionCode"] != System.DBNull.Value && ((dvRequest[j]["sectionCode"]).ToString() == "1405-TBC" || (dvRequest[j]["sectionCode"]).ToString() == "1405-TBC2" || (dvRequest[j]["sectionCode"]).ToString() == "1405-TBC3"))
                                cOrto++;
                            if (dvRequest[j]["sectionCode"] != System.DBNull.Value && ((dvRequest[j]["sectionCode"]).ToString() == "1405-PF" || (dvRequest[j]["sectionCode"]).ToString() == "1405-PF2" || (dvRequest[j]["sectionCode"]).ToString() == "1405-PF3"))
                                cPulm++;
                        }

                        dvRequest.RowFilter = "";

                        phCommonReport.Controls.Add(new LiteralControl("<tr>"));
                        phCommonReport.Controls.Add(new LiteralControl("<td class='tdnleft' width='2%'>" + counter.ToString() + "</td>"));
                        phCommonReport.Controls.Add(new LiteralControl("<td class='tdnleft' width='40%'>" + dvRequest[i]["name"].ToString() + "</td>"));
                        phCommonReport.Controls.Add(new LiteralControl("<td class='tdnright' width='5%'>" + age0_14.ToString() + "</td>"));
                        phCommonReport.Controls.Add(new LiteralControl("<td class='tdnright' width='5%'>" + age15_24.ToString() + "</td>"));
                        phCommonReport.Controls.Add(new LiteralControl("<td class='tdnright' width='5%'>" + age25_39.ToString() + "</td>"));
                        phCommonReport.Controls.Add(new LiteralControl("<td class='tdnright' width='5%'>" + age40_59.ToString() + "</td>"));
                        phCommonReport.Controls.Add(new LiteralControl("<td class='tdnright' width='5%'>" + age60_79.ToString() + "</td>"));
                        phCommonReport.Controls.Add(new LiteralControl("<td class='tdnright' width='5%'>" + age80.ToString() + "</td>"));
                        phCommonReport.Controls.Add(new LiteralControl("<td class='tdnright' width='2%'>" + cF.ToString() + "</td>"));
                        phCommonReport.Controls.Add(new LiteralControl("<td class='tdnright' width='2%'>" + cM.ToString() + "</td>"));
                        phCommonReport.Controls.Add(new LiteralControl("<td class='tdnright' width='5%'>" + cUrban.ToString() + "</td>"));
                        phCommonReport.Controls.Add(new LiteralControl("<td class='tdnright' width='5%'>" + cRural.ToString() + "</td>"));
                        phCommonReport.Controls.Add(new LiteralControl("<td class='tdnright' width='5%'>" + cOrto.ToString() + "</td>"));
                        phCommonReport.Controls.Add(new LiteralControl("<td class='tdnright' width='5%'>" + cPulm.ToString() + "</td>"));
                        phCommonReport.Controls.Add(new LiteralControl("<td class='tdnright' width='5%'>" + cTotal.ToString() + "</td>"));

                        phCommonReport.Controls.Add(new LiteralControl("</tr>"));

                        age0_14 = 0;
                        age15_24 = 0;
                        age25_39 = 0;
                        age40_59 = 0;
                        age60_79 = 0;
                        age80 = 0;
                        cF = 0;
                        cM = 0;
                        cUrban = 0;
                        cRural = 0;
                        cTotal = 0;
                        cOrto = 0;
                        cPulm = 0;

                        counter++;
                    }
                }
            }

            phCommonReport.Controls.Add(new LiteralControl("</tbody>"));
            phCommonReport.Controls.Add(new LiteralControl("<tfoot style='display:table-footer-group'>"));
            phCommonReport.Controls.Add(new LiteralControl("<tr>"));
            phCommonReport.Controls.Add(new LiteralControl("<td colspan=8>&nbsp;</td>"));
            phCommonReport.Controls.Add(new LiteralControl("</tr>"));
            phCommonReport.Controls.Add(new LiteralControl("</tfoot>"));
            phCommonReport.Controls.Add(new LiteralControl("</table>"));

            phCommonReport.Controls.Add(new LiteralControl("</br></br></br>"));
            phCommonReport.Controls.Add(new LiteralControl("<table border='0' cellpadding='0' cellspacing='0' width='100%' ID='Table3'>"));
            phCommonReport.Controls.Add(new LiteralControl("<tr height='40'>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdleft' colspan='2'>Raspundem de realitatea si exactitatea datelor</td>"));
            phCommonReport.Controls.Add(new LiteralControl("</tr>"));
            phCommonReport.Controls.Add(new LiteralControl("<tr height='40'>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdleft'>Reprezentant legal al cabinetului</td>"));
            phCommonReport.Controls.Add(new LiteralControl("<td class='tdright'>Semnatura si parafa medicului</td>"));
            phCommonReport.Controls.Add(new LiteralControl("</tr>"));
            phCommonReport.Controls.Add(new LiteralControl("</table>"));

        }
        catch (Exception ex)
        {
            message.Text = ex.ToString();
        }
    }

    protected void CASLPrivat(CommonSession.StareRapoarteLaborator info)
    {
        try
        {
            string querystring = @"select distinct [Domain] as Class from LAB_DOMAINS WHERE 1=1 ";

            if (info.groupByTypes != "*")
                querystring += " AND [Domain] in " + info.groupByTypes;

            querystring += " order by Class";

            sb.Append("<table width=\"100%\" border=\"0\">");
            sb.Append("<tr>");
            sb.Append("<td valign=top align=\"left\" valign=\"top\">");
            sb.Append("<span>Casa de asigurari de sanatate ................................</span><br/>");
            sb.Append("<span>Unitatea sanitara ................................</span><br/>");
            sb.Append("<span>Localitatea ................................</span><br/>");
            sb.Append("<span>Judetul ................................</span><br/>");
            sb.Append("</td>");
            sb.Append("<td valign=top align=\"right\" valign=\"top\">");
            sb.Append(siglaRSC());
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td align=\"center\" colspan=\"2\">");
            sb.Append("<span class=\"H2\">Desfasurator lunar al investigatiilor paraclinice efectuate</span><br>");
            sb.Append("<span class=\"H3\">" + info.startDate + " - " + info.endDate + "</span><br></br>");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            sb.Append("<table border='1' cellpadding='0' cellspacing='0' width='100%'>");
            sb.Append("<thead>");
            sb.Append("<tr>");
            sb.Append("<td class='tdnplusleft' rowspan='2' width='2%'>&nbsp;Nr.<br>Crt</td>");
            sb.Append("<td class='tdnplusleft' rowspan='2' width='38%'>Tipul investigatiei paraclinice/ (codul)</td>");
            sb.Append("<td class='tdnplusleft' rowspan='2' width='10%'>Codul investigatiei</td>");
            sb.Append("<td class='tdnplusleft' colspan='2' width='10%'>Total investigatii paraclinice</td>");
            sb.Append("<td class='tdnplusleft' rowspan='2' width='30%'>Tarif negociat / investigatie paraclinica stabilita la contractare</td>");
            sb.Append("<td class='tdnplusleft' colspan='2' width='10%'>Sume lei</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td class='tdnplus' width='5%'>Efectuate</td>");
            sb.Append("<td class='tdnplus' width='5%'>- din care urgente</td>");
            sb.Append("<td class='tdnplus' width='5%'>Total general</td>");
            sb.Append("<td class='tdnplus' width='5%'>- din care urgente</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td class='tdnplus' width='2%'>C1</td>");
            sb.Append("<td class='tdnplus' width='38%'>C2</td>");
            sb.Append("<td class='tdnplus' width='10%'>C3</td>");
            sb.Append("<td class='tdnplus' width='5%'>C4</td>");
            sb.Append("<td class='tdnplus' width='5%'>C5</td>");
            sb.Append("<td class='tdnplus' width='30%'>C6</td>");
            sb.Append("<td class='tdnplus' width='5%'>C7=C4*C6</td>");
            sb.Append("<td class='tdnplus' width='5%'>C8=C5*C6</td>");
            sb.Append("</tr>");
            sb.Append("</tr>");
            sb.Append("</thead>");
            sb.Append("<tbody>");

            DataSet dsRequest = Hipocrate.DB.DBConnection.GetData(querystring.Replace("&nbsp;", " "));
            DataView dvRequest = dsRequest.Tables[0].DefaultView;
            decimal totalContor = 0;
            decimal totalCost = 0;

            if (dvRequest.Count > 0)
            {
                string prevClass = "";

                for (int i = 0; i < dvRequest.Count; ++i)
                {
                    prevClass = dvRequest[i]["class"].ToString();

                    sb.Append("<tr>");
                    sb.Append("<td class='tdnplusleft' width='100%' colspan='8'>" + dvRequest[i]["class"].ToString() + "</td>");
                    sb.Append("</tr>");

                    string queryAnalyseTypes = "select distinct CASName, CASCode from vAnalyseTypes";
                    queryAnalyseTypes += " where Class='" + dvRequest[i]["class"].ToString() + "'";
                    if (!info.bInactiveToo)
                        queryAnalyseTypes += " AND Active = 1 ";
                    if (!info.bUnpaidToo)
                        queryAnalyseTypes += " AND IsCASPayable = 1 ";
                    queryAnalyseTypes += " order by CASCode, CASName";

                    DataSet dsAnalyseTypes = Hipocrate.DB.DBConnection.GetData(queryAnalyseTypes);
                    DataView dvAnalyseTypes = dsAnalyseTypes.Tables[0].DefaultView;

                    decimal classCost = 0;

                    decimal tempContor = 0;

                    for (int j = 0; j < dvAnalyseTypes.Count; ++j)
                    {
                        string queryCosts = "select count(*) AS NR from vRequestClass where DeletedID IS NULL and Submited=1 ";
                        queryCosts += " AND CASAnalyseName='" + dvAnalyseTypes[j]["CASName"].ToString() + "'";
                        queryCosts += " AND CASAnalyseCode='" + dvAnalyseTypes[j]["CASCode"].ToString() + "'";
                        queryCosts += " AND Class='" + dvRequest[i]["class"].ToString() + "'";

                        if (info.groupBySection != "*" && !string.IsNullOrEmpty(info.groupBySection))
                            queryCosts += " AND SectionCode in " + info.groupBySection;

                        if (!string.IsNullOrEmpty(info.strPayType))
                            queryCosts += " AND PaymentTypeID = " + info.strPayType;

                        if (!info.bInactiveToo)
                            queryCosts += " AND Active = 1 ";

                        if (!info.bUnpaidToo)
                            queryCosts += " AND IsCASPayable = 1 ";

                        if (info.bProcessed)
                            queryCosts += " AND Status > 0 ";

                        queryCosts += " AND IsEmergency = 1 ";

                        queryCosts += "  AND PaymentTypeID = " + info.strPayType;

                        if (info.startDate != null && info.endDate != null)
                            queryCosts += " AND requestedDate between '" + Tools.getSQLFormat_120(info.startDate) + "' AND '" + Tools.getSQLFormat_120(info.endDate) + "' ";

                        queryCosts += " group by CASAnalyseName, CASAnalyseCode";

                        DataSet dsQueryCosts = Hipocrate.DB.DBConnection.GetData(queryCosts.Replace("AND IsEmergency = 1", " ") + ";" + queryCosts);
                        DataView dvQueryCosts = dsQueryCosts.Tables[0].DefaultView;
                        DataView dvQueryCosts2 = dsQueryCosts.Tables[1].DefaultView;

                        string queryAnalyseID = "select top 1 ID from Analyse_Types where [CASName]='" + dvAnalyseTypes[j]["CASName"].ToString() + "'";
                        DataSet dsAnalyseID = Hipocrate.DB.DBConnection.GetData(queryAnalyseID);
                        DataView dvAnalyseID = dsAnalyseID.Tables[0].DefaultView;

                        string querySum = "select SUM(ISNULL(Qty, 0)*ISNULL(Price, 0)) as analyseCost from vAnalyseType_Costs where ID=" + dvAnalyseID[0]["ID"].ToString();
                        querySum += "AND CONVERT(DATETIME, '" + Tools.getSQLFormat_103(info.endDate) + "', 103) between startDate AND ISNULL(endDate, CONVERT(DATETIME, '" + Tools.getSQLFormat_103(info.endDate) + "', 103)) AND PaymentTypeID=" + info.strPayType;
                        DataSet dsQuerySum = Hipocrate.DB.DBConnection.GetData(querySum);
                        DataView dvQuerySum = dsQuerySum.Tables[0].DefaultView;


                        decimal NRTemp = (dvQueryCosts.Count > 0 ? (dvQueryCosts[0]["NR"] != System.DBNull.Value ? Convert.ToDecimal(dvQueryCosts[0]["NR"]) : 0) : 0);
                        decimal costTemp = (dvQuerySum.Count > 0 ? (dvQuerySum[0]["analyseCost"] != System.DBNull.Value ? Convert.ToDecimal(dvQuerySum[0]["analyseCost"]) : 0) : 0);
                        decimal emrgencyTemp = (dvQueryCosts2.Count > 0 ? (dvQueryCosts2[0]["NR"] != System.DBNull.Value ? Convert.ToDecimal(dvQueryCosts2[0]["NR"]) : 0) : 0);

                        sb.Append("<tr>");
                        sb.Append("<td class='tdnleft' width='2%'>" + (j + 1).ToString() + "</td>");
                        sb.Append("<td class='tdnleft' width='38%'>" + dvAnalyseTypes[j]["CASName"].ToString() + "</td>");
                        sb.Append("<td class='tdnleft' width='10%'>" + dvAnalyseTypes[j]["CASCode"].ToString() + "</td>");
                        sb.Append("<td class='tdnright' width='5%'>" + NRTemp + "</td>");
                        sb.Append("<td class='tdnright' width='5%'>" + emrgencyTemp + "</td>");
                        sb.Append("<td class='tdnright' width='30%'>" + costTemp.ToString("0.00") + "</td>");
                        sb.Append("<td class='tdnright' width='5%'>" + (NRTemp * costTemp).ToString("0.00") + "</td>");
                        sb.Append("<td class='tdnright' width='5%'>" + (emrgencyTemp * costTemp).ToString("0.00") + "</td>");
                        sb.Append("</tr>");

                        tempContor += NRTemp;
                        classCost += (NRTemp * costTemp);
                        totalCost += (NRTemp * costTemp);
                        totalContor += NRTemp;
                    }

                    sb.Append("<tr>");
                    sb.Append("<td class='tdnplusleft' width='40%' colspan='2'>Total:" + dvRequest[i]["class"].ToString() + "</td>");
                    sb.Append("<td class='tdnright' width='10%'>" + tempContor + "</td>");
                    sb.Append("<td class='tdnright' width='50%' colspan='2'>" + classCost.ToString("0.00") + "</td>");
                    sb.Append("<td class='tdnright' width='50%' colspan='3'>&nbsp;</td>");
                    sb.Append("</tr>");
                }

                sb.Append("<tr>");
                sb.Append("<td class='tdnplusleft' width='40%' colspan='2'>Total General:</td>");
                sb.Append("<td class='tdnplusleft' width='10%'>" + totalContor + "</td>");
                sb.Append("<td class='tdnplusleft' width='50%' colspan='2'>" + totalCost.ToString("0.00") + "</td>");
                sb.Append("<td class='tdnright' width='50%' colspan='3'>&nbsp;</td>");
                sb.Append("</tr>");
            }

            sb.Append("</tbody>");
            sb.Append("</table>");

            sb.Append("</br></br></br>");
            sb.Append("<table border='0' cellpadding='0' cellspacing='0' width='100%' ID='Table3'>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft' colspan='2'>Raspundem de realitatea si exactitatea datelor</td>");
            sb.Append("</tr>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft'>Reprezentant legal al cabinetului</td>");
            sb.Append("<td class='tdright'>Semnatura si parafa medicului</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            phCommonReport.Controls.Add(new LiteralControl(sb.ToString()));

        }
        catch (Exception ex)
        {
            message.Text = ex.ToString();
        }
    }

    protected void nominalCASPrivate(CommonSession.StareRapoarteLaborator info)
    {
        try
        {
            string querystring = @"select V.ID, V.Requested as ReqDate, V.LastName, V.FirstName, V.CNP,  S.LastName as MedicLastName, S.FirstName as MedicFirstName, 
                V.MedicID, S.StampNo, S.ContractNo, V.Priority  from vListLabRequests V left join Staff S on V.MedicID = S.[ID] where V.DeletedID is null and V.Submited=1 ";

            if (info.groupBySection != "*" && !string.IsNullOrEmpty(info.groupBySection))
                querystring += " AND V.SectionCode in " + info.groupBySection;

            if (info.groupByTypes != "*")
            {
                querystring += "AND exists (SELECT * FROM vAnalyseMachines VM join ANALYSES A on VM.AnalyseID = A.TypeID ";
                querystring += "AND A.RequestID=V.ID ";
                querystring += "AND VM.MachineClass IN " + info.groupByTypes + ") ";
            }

            if (info.startDate != null && info.endDate != null)
                querystring += " AND V.RequestedDate between '" + Tools.getSQLFormat_120(info.startDate) + "' AND '" + Tools.getSQLFormat_120(info.endDate) + "' ";


            if (!string.IsNullOrEmpty(info.strPayType))
            {
                querystring += " and exists (SELECT a.* FROM ANALYSES a INNER JOIN LAB_REQUESTS lr ON lr.ID = a.RequestID ";
                querystring += "  WHERE ( lr.RequestedDate between '" + Tools.getSQLFormat_120(info.startDate) + "' AND '" + Tools.getSQLFormat_120(info.endDate) + "') AND (a.PaymentTypeID = " + info.strPayType + ")) ";
            }

            querystring += " order by RequestedDate, V.LastName, V.FirstName";

            sb.Append("<table width=\"100%\" border=\"0\">");
            sb.Append("<tr>");
            sb.Append("<td valign=top align=\"left\" valign=\"top\">");
            sb.Append("<span>Casa de asigurari de sanatate ................................</span><br/>");
            sb.Append("<span>Unitatea sanitara ................................</span><br/>");
            sb.Append("<span>Localitatea ................................</span><br/>");
            sb.Append("<span>Judetul ................................</span><br/>");
            sb.Append("</td>");
            sb.Append("<td valign=top align=\"right\" valign=\"top\">");
            sb.Append(siglaRSC());
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td align=\"center\" colspan=\"2\">");
            sb.Append("<span class=\"H2\">Lista pacientilor care au beneficiat de investigatii paraclinice</span><br>");
            sb.Append("<span class=\"H3\">" + info.startDate + " - " + info.endDate + "</span><br></br>");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            sb.Append("<table border='1' cellpadding='0' cellspacing='0' width='100%' ID='Table1'>");
            sb.Append("<tr>");
            sb.Append("<td class='tdnplusleft' width='2%'>&nbsp;Nr.<br>Crt</td>");
            sb.Append("<td class='tdnplusleft' width='8%'>CNP</td>");
            sb.Append("<td class='tdnplusleft' width='50%'>Tipul investigatiei paraclinice efectuate</td>");
            sb.Append("<td class='tdnplusleft' width='20%'>Codul investigatiei paraclinice efectuate</td>");
            sb.Append("<td class='tdnplusleft' width='20%'>Tariful investigatiei efectuate (lei)</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td class='tdnplusleft' width='2%'>C1</td>");
            sb.Append("<td class='tdnplusleft' width='8%'>C2</td>");
            sb.Append("<td class='tdnplusleft' width='50%'>C3</td>");
            sb.Append("<td class='tdnplusleft' width='20%'>C4</td>");
            sb.Append("<td class='tdnplusleft' width='20%'>C5</td>");
            sb.Append("</tr>");

            DataSet dsRequest = Hipocrate.DB.DBConnection.GetData(querystring);
            DataView dvRequest = dsRequest.Tables[0].DefaultView;
            decimal totalContor = 0;
            decimal totalCost = 0;

            if (dvRequest.Count > 0)
            {

                for (int i = 0; i < dvRequest.Count; ++i)
                {
                    string queryAnalyseTypes = "";

                    if (info.bInternalCode)
                        queryAnalyseTypes += "select V.TypeID, V.AnalyseCode as Code, V.AnalyseName as Name from vRequestClass V ";
                    else
                        queryAnalyseTypes += "select V.TypeID, V.CASAnalyseCode as Code, V.CASAnalyseName as Name from vRequestClass V ";

                    queryAnalyseTypes += " where RequestID = " + dvRequest[i]["ID"].ToString();

                    if (!info.bInactiveToo)
                        queryAnalyseTypes += " AND V.Active = 1 ";

                    if (!info.bUnpaidToo)
                        queryAnalyseTypes += " AND IsCASPayable = 1 ";

                    if (info.groupByTypes != "*")
                        queryAnalyseTypes += " AND V.[Class] IN " + info.groupByTypes + ") ";

                    if (info.bProcessed)
                        queryAnalyseTypes += " AND V.Status > 0 ";

                    if (info.bTehnice)
                        queryAnalyseTypes += " AND V.Test <> 1 ";

                    queryAnalyseTypes += " AND (v.PaymentTypeID=" + info.strPayType + ") ";

                    if (info.bInternalCode)
                        queryAnalyseTypes += " order by V.CASAnalyseCode ";
                    else
                        queryAnalyseTypes += " order by V.CASAnalyseName ";

                    DataSet dsAnalyseTypes = Hipocrate.DB.DBConnection.GetData(queryAnalyseTypes);
                    DataView dvAnalyseTypes = dsAnalyseTypes.Tables[0].DefaultView;

                    for (int j = 0; j < dvAnalyseTypes.Count; ++j)
                    {
                        string querySum = "select SUM(ISNULL(Qty, 0)*ISNULL(Price, 0)) as analyseCost from vAnalyseType_Costs where ID=" + dvAnalyseTypes[j]["TypeID"].ToString();
                        querySum += "AND CONVERT(DATETIME, '" + Tools.getSQLFormat_120(info.endDate) + "', 103) between startDate AND ISNULL(endDate, CONVERT(DATETIME, '" + Tools.getSQLFormat_120(info.endDate) + "', 103)) AND PaymentTypeID=" + info.strPayType;
                        DataSet dsQuerySum = Hipocrate.DB.DBConnection.GetData(querySum);
                        DataView dvQuerySum = dsQuerySum.Tables[0].DefaultView;

                        decimal costTemp = (dvQuerySum.Count > 0 ? (dvQuerySum[0]["analyseCost"] != System.DBNull.Value ? Convert.ToDecimal(dvQuerySum[0]["analyseCost"]) : 0) : 0);

                        sb.Append("<tr>");
                        sb.Append("<td class='tdn' width='2%'>" + (i + 1).ToString() + "</td>");
                        sb.Append("<td class='tdn' width='8%'>" + (dvRequest[i]["CNP"] != System.DBNull.Value ? dvRequest[i]["CNP"].ToString() : "&nbsp;") + "</td>");
                        sb.Append("<td class='tdnleft' width='50%'>" + (dvAnalyseTypes.Count > 0 ? dvAnalyseTypes[j]["Name"].ToString() : "") + "</td>");
                        sb.Append("<td class='tdnleft' width='20%'>" + (dvAnalyseTypes.Count > 0 ? dvAnalyseTypes[j]["Code"].ToString() : "") + "</td>");
                        sb.Append("<td class='tdnright' width='20%'>" + costTemp.ToString("0.00") + "</td>");
                        sb.Append("</tr>");

                        totalContor++;
                        totalCost += costTemp;
                    }

                }

                sb.Append("<tr>");
                sb.Append("<td class='tdnplusleft' width='60%' colspan='3'>Total General:</td>");
                sb.Append("<td class='tdnplusright' width='20%'>" + totalContor + "</td>");
                sb.Append("<td class='tdnplusright' width='20%'>" + totalCost.ToString("0.00") + "</td>");
                sb.Append("</tr>");
            }

            sb.Append("</table>");

            sb.Append("</br></br></br>");
            sb.Append("<table border='0' cellpadding='0' cellspacing='0' width='100%' ID='Table3'>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft' colspan='2'>Raspundem de realitatea si exactitatea datelor</td>");
            sb.Append("</tr>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft'>Reprezentant legal al cabinetului</td>");
            sb.Append("<td class='tdright'>Semnatura si parafa medicului</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            phCommonReport.Controls.Add(new LiteralControl(sb.ToString()));

        }
        catch (Exception ex)
        {
            message.Text = ex.ToString();
        }
    }

    protected void centralizerCAS_VAL(CommonSession.StareRapoarteLaborator info)
    {
        try
        {
            string querystring = @"select distinct [Domain] as Class from LAB_DOMAINS WHERE 1=1 ";

            if (info.groupByTypes != "*")
            {
                querystring += " AND [Domain] in " + info.groupByTypes;
            }

            querystring += " order by [Domain]";

            sb.Append("<table width=\"100%\" border=\"0\">");
            sb.Append("<tr>");
            sb.Append("<td valign=top align=\"left\" valign=\"top\">");
            sb.Append("<span class=\"H3\">Spitalul Clinic de Urgenta pentru Copii 'GRIGORE ALEXANDRESCU'</span>");
            sb.Append("</td>");
            sb.Append("<td valign=top align=\"right\" valign=\"top\">");
            sb.Append(siglaRSC());
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td align=\"center\" colspan=\"2\">");
            sb.Append("<span class=\"H2\">CENTRALIZATOR CU VALOAREA INVESTIGATIILOR PARACLINICE <br/>PE SECTII/TIP DE INVESTIGATII</span><br>");
            sb.Append("<span class=\"H3\">din " + info.startDate + " pana in " + info.endDate + "</span><br></br>");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            sb.Append("<table border='1' cellpadding='0' cellspacing='0' width='100%' ID='Table1'>");
            sb.Append("<tr>");
            sb.Append("<td class='tdnplusleft' width='10%' colspan='2'>&nbsp;</td>");

            DataSet dsRequest = Hipocrate.DB.DBConnection.GetData(querystring.Replace("&nbsp;", " "));
            DataView dvRequest = dsRequest.Tables[0].DefaultView;

            if (dvRequest.Count > 0)
            {
                for (int i = 0; i < dvRequest.Count; ++i)
                {
                    sb.Append("<td class='tdnplusleft' width='5%'>&nbsp;" + dvRequest[i]["Class"].ToString() + "&nbsp;</td>");
                }
            }

            sb.Append("<td class='tdnplusleft' width='5%'>TOTAL</td>");
            sb.Append("</tr>");

            string querySections = @"select distinct s.Code, s.Name, s.Ambulatory, s.Guard, s.Therapy, s.Clinic from SECTIONS s where 1=1
                                and (s.Ambulatory=1 or s.Guard=1 or s.Therapy=1 or s.Clinic=1)
                                order by s.Ambulatory desc, s.Guard desc, s.Therapy desc, s.Name";

            DataSet dsSections = Hipocrate.DB.DBConnection.GetData(querySections);
            DataView dvSections = dsSections.Tables[0].DefaultView;

            if (dvSections.Count > 0)
            {
                for (int j = 0; j < dvSections.Count; ++j)
                {
                    sb.Append("<tr>");
                    sb.Append("<td class='tdnplusleft' width='2%'>" + (j + 1).ToString() + "</td>");
                    sb.Append("<td class='tdnplusleft' width='8%'>" + dvSections[j]["Name"].ToString() + "</td>");

                    decimal totalCost = 0;
                    for (int k = 0; k < dvRequest.Count; ++k)
                    {
                        int count = 0;
                        decimal tmp = 0, cost = 0;

                        string queryAnalyse = @"select distinct ISNULL(CASName, Name) as CASName, ISNULL(CASCode, Code) AS CASCode from vAnalyseTypes ";
                        queryAnalyse += "where Class='" + dvRequest[k]["Class"].ToString() + "'";

                        if (!info.bInactiveToo)
                            queryAnalyse += " AND Active = 1 ";

                        if (!info.bUnpaidToo)
                            queryAnalyse += " AND IsCASPayable = 1 ";

                        queryAnalyse += " order by CASName, CASCode ";

                        DataSet dsAnalyse = Hipocrate.DB.DBConnection.GetData(queryAnalyse);
                        DataView dvAnalyse = dsAnalyse.Tables[0].DefaultView;

                        if (dvAnalyse.Count > 0)
                        {
                            for (int w = 0; w < dvAnalyse.Count; ++w)
                            {
                                string queryRequestClass = @"select count(*) AS NR from vRequestClass where DeletedID is null and Submited=1";
                                queryRequestClass += " AND CASAnalyseName='" + dvAnalyse[w]["CASName"].ToString() + "'";
                                queryRequestClass += " AND CASAnalyseCode='" + dvAnalyse[w]["CASCode"].ToString() + "'";
                                queryRequestClass += " AND Class='" + dvRequest[k]["Class"].ToString() + "'";
                                queryRequestClass += " AND SectionCode='" + dvSections[j]["Code"].ToString() + "'";

                                if (info.bSpecifiedPayType)
                                    queryRequestClass += " AND PaymentTypeID = " + info.strPayType;
                                if (info.bProcessed)
                                    queryRequestClass += " AND status > 0 ";
                                if (info.bTehnice)
                                    queryRequestClass += " AND test <> 1 ";

                                queryRequestClass += " AND requestedDate between '" + Tools.getSQLFormat_120(info.startDate) + "' AND '" + Tools.getSQLFormat_120(info.endDate) + "' ";
                                queryRequestClass += " group by CASAnalyseName, CASAnalyseCode";

                                DataSet dsRequestClass = Hipocrate.DB.DBConnection.GetData(queryRequestClass);
                                DataView dvRequestClass = dsRequestClass.Tables[0].DefaultView;

                                if (dvRequestClass.Count > 0)
                                    count += Convert.ToInt32(dvRequestClass[0]["NR"]);

                                string queryAnalyseID = "select top 1 ID from Analyse_Types where [CASName]='" + dvAnalyse[w]["CASName"].ToString() + "'";
                                DataSet dsAnalyseID = Hipocrate.DB.DBConnection.GetData(queryAnalyseID);
                                DataView dvAnalyseID = dsAnalyseID.Tables[0].DefaultView;

                                string querySum = "select SUM(ISNULL(Qty, 0)*ISNULL(Price, 0)) as analyseCost from vAnalyseType_Costs where ID=" + dvAnalyseID[0]["ID"].ToString();
                                querySum += "AND CONVERT(DATETIME, '" + Tools.getSQLFormat_103(info.endDate) + "', 103) between startDate AND ISNULL(endDate, CONVERT(DATETIME, '" + Tools.getSQLFormat_103(info.endDate) + "', 103)) AND PaymentTypeID=" + info.strPayType;
                                DataSet dsQuerySum = Hipocrate.DB.DBConnection.GetData(querySum);
                                DataView dvQuerySum = dsQuerySum.Tables[0].DefaultView;

                                tmp = (dvQuerySum.Count > 0 ? (dvQuerySum[0]["analyseCost"] != System.DBNull.Value ? Convert.ToDecimal(dvQuerySum[0]["analyseCost"]) : 0) : 0);
                                cost = count * tmp;
                            }
                        }

                        totalCost += cost;

                        sb.Append("<td class='tdnright' width='5%'>" + cost.ToString("0.00") + "</td>");
                    }
                    sb.Append("<td class='tdnright' width='5%'>" + totalCost.ToString("0.00") + "</td>");
                    sb.Append("</tr>");
                }
            }

            sb.Append("</table>");

            sb.Append("</br></br></br>");
            sb.Append("<table border='0' cellpadding='0' cellspacing='0' width='100%' ID='Table3'>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft' colspan='2'>Raspundem de realitatea si exactitatea datelor</td>");
            sb.Append("</tr>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft'>Reprezentant legal al cabinetului</td>");
            sb.Append("<td class='tdright'>Semnatura si parafa medicului</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            phCommonReport.Controls.Add(new LiteralControl(sb.ToString()));

        }
        catch (Exception ex)
        {
            message.Text = ex.ToString();
        }
    }

    protected void centralizerCAS(CommonSession.StareRapoarteLaborator info)
    {
        try
        {
            string querySections = @"select distinct s.Code, s.Name, s.Ambulatory, s.Guard, s.Therapy, s.Clinic from SECTIONS s where 1=1
                                and (s.Ambulatory=1 or s.Guard=1 or s.Therapy=1 or s.Clinic=1)
                                order by s.Ambulatory desc, s.Guard desc, s.Therapy desc, s.Name";

            sb.Append("<table width=\"100%\" border=\"0\">");
            sb.Append("<tr>");
            sb.Append("<td valign=top align=\"left\" valign=\"top\">");
            sb.Append("<span class=\"H3\">Spitalul Clinic de Urgenta pentru Copii 'GRIGORE ALEXANDRESCU'</span>");
            sb.Append("</td>");
            sb.Append("<td valign=top align=\"right\" valign=\"top\">");
            sb.Append(siglaRSC());
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td align=\"center\" colspan=\"2\">");
            sb.Append("<span class=\"H2\">CENTRALIZATOR INVESTIGATII PARACLINICE</span><br>");
            sb.Append("<span class=\"H3\">din " + info.startDate + " pana in " + info.endDate + "</span><br></br>");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            sb.Append("<table border='1' cellpadding='0' cellspacing='0' width='100%' ID='Table1'>");
            sb.Append("<tr>");
            sb.Append("<td class='tdnplusleft' width='30%'>&nbsp;</td>");
            sb.Append("<td class='tdnplusleft' width='5%'>COD ANALIZA</td>");

            DataSet dsSections = Hipocrate.DB.DBConnection.GetData(querySections);
            DataView dvSections = dsSections.Tables[0].DefaultView;

            if (dvSections.Count > 0)
            {
                for (int i = 0; i < dvSections.Count; ++i)
                {
                    sb.Append("<td class='tdnplusleft' style='writing-mode:tb-rl;'>&nbsp;" + dvSections[i]["Code"].ToString() + "&nbsp;</td>");
                }
            }

            sb.Append("<td class='tdnplusleft' width='5%'>TOTAL</td>");
            sb.Append("</tr>");

            string queryClass = @"select distinct [Domain] as Class from LAB_DOMAINS WHERE 1=1 ";

            if (info.groupByTypes != "*")
            {
                queryClass += " AND [Domain] in " + info.groupByTypes;
            }

            queryClass += " order by [Domain]";

            DataSet dsClass = Hipocrate.DB.DBConnection.GetData(queryClass.Replace("&nbsp;", " "));
            DataView dvClass = dsClass.Tables[0].DefaultView;
            string prevClass = "";

            if (dvClass.Count > 0)
            {
                for (int j = 0; j < dvClass.Count; ++j)
                {
                    string queryAnalyse = @"select distinct ISNULL(CASName, Name) as CASName, ISNULL(CASCode, Code) AS CASCode from vAnalyseTypes ";
                    queryAnalyse += "where Class='" + dvClass[j]["Class"].ToString() + "'";

                    if (!info.bInactiveToo)
                        queryAnalyse += " AND Active = 1 ";

                    if (!info.bUnpaidToo)
                        queryAnalyse += " AND IsCASPayable = 1 ";

                    queryAnalyse += " order by CASName, CASCode ";

                    DataSet dsAnalyse = Hipocrate.DB.DBConnection.GetData(queryAnalyse);
                    DataView dvAnalyse = dsAnalyse.Tables[0].DefaultView;

                    if (dvClass[j]["class"].ToString() != prevClass)
                    {
                        prevClass = dvClass[j]["class"].ToString();
                        sb.Append("<tr>");
                        sb.Append("<td class='tdnplusleft' width='100%' colspan='" + (dvSections.Count + 3) + "'>" + dvClass[j]["Class"].ToString() + "</td>");
                        sb.Append("</tr>");
                    }

                    int count = 0;
                    int countClass = 0;
                    decimal totalCount = 0;
                    decimal totalCountClass = 0;
                    decimal totalCost = 0;
                    decimal tmp = 0;
                    decimal cost = 0;

                    for (int k = 0; k < dvAnalyse.Count; ++k)
                    {
                        sb.Append("<tr>");
                        sb.Append("<td class='tdnleft' width='30%' rowspan='2'>" + dvAnalyse[k]["CASName"].ToString() + "</td>");
                        sb.Append("<td class='tdnleft' width='5%' rowspan='2'>" + dvAnalyse[k]["CASCode"].ToString() + "</td>");

                        for (int x = 0; x < dvSections.Count; ++x)
                        {
                            string queryRequestClass = @"select count(*) AS NR from vRequestClass where DeletedID is null and Submited=1";
                            queryRequestClass += " AND CASAnalyseName='" + dvAnalyse[k]["CASName"].ToString() + "'";
                            queryRequestClass += " AND CASAnalyseCode='" + dvAnalyse[k]["CASCode"].ToString() + "'";
                            queryRequestClass += " AND Class='" + dvClass[j]["Class"].ToString() + "'";
                            queryRequestClass += " AND SectionCode='" + dvSections[x]["Code"].ToString() + "'";

                            if (info.bSpecifiedPayType)
                                queryRequestClass += " AND PaymentTypeID = " + info.strPayType;
                            if (info.bProcessed)
                                queryRequestClass += " AND status > 0 ";
                            if (info.bTehnice)
                                queryRequestClass += " AND test <> 1 ";

                            queryRequestClass += " AND requestedDate between '" + Tools.getSQLFormat_120(info.startDate) + "' AND '" + Tools.getSQLFormat_120(info.endDate) + "' ";
                            queryRequestClass += " group by CASAnalyseName, CASAnalyseCode";

                            DataSet dsRequestClass = Hipocrate.DB.DBConnection.GetData(queryRequestClass);
                            DataView dvRequestClass = dsRequestClass.Tables[0].DefaultView;

                            if (dvRequestClass.Count > 0)
                                count += Convert.ToInt32(dvRequestClass[0]["NR"]);

                            totalCount += count;

                            sb.Append("<td class='tdn'>" + (count == 0 ? "-" : count.ToString()) + "</td>");
                            count = 0;
                        }
                        sb.Append("<td class='tdn' >" + (totalCount == 0 ? "0" : totalCount.ToString()) + "</td>");
                        sb.Append("</tr>");

                        sb.Append("<tr>");
                        for (int x = 0; x < dvSections.Count; ++x)
                        {
                            string queryRequestClass = @"select count(*) AS NR from vRequestClass where DeletedID is null and Submited=1";
                            queryRequestClass += " AND CASAnalyseName='" + dvAnalyse[k]["CASName"].ToString() + "'";
                            queryRequestClass += " AND CASAnalyseCode='" + dvAnalyse[k]["CASCode"].ToString() + "'";
                            queryRequestClass += " AND Class='" + dvClass[j]["Class"].ToString() + "'";
                            queryRequestClass += " AND SectionCode='" + dvSections[x]["Code"].ToString() + "'";

                            if (info.bSpecifiedPayType)
                                queryRequestClass += " AND PaymentTypeID = " + info.strPayType;
                            if (info.bProcessed)
                                queryRequestClass += " AND status > 0 ";
                            if (info.bTehnice)
                                queryRequestClass += " AND test <> 1 ";

                            queryRequestClass += " AND requestedDate between '" + Tools.getSQLFormat_120(info.startDate) + "' AND '" + Tools.getSQLFormat_120(info.endDate) + "' ";
                            queryRequestClass += " group by CASAnalyseName, CASAnalyseCode";

                            DataSet dsRequestClass = Hipocrate.DB.DBConnection.GetData(queryRequestClass);
                            DataView dvRequestClass = dsRequestClass.Tables[0].DefaultView;

                            if (dvRequestClass.Count > 0)
                                count += Convert.ToInt32(dvRequestClass[0]["NR"]);

                            string queryAnalyseID = "select top 1 ID from Analyse_Types where [CASName]='" + dvAnalyse[k]["CASName"].ToString() + "'";
                            DataSet dsAnalyseID = Hipocrate.DB.DBConnection.GetData(queryAnalyseID);
                            DataView dvAnalyseID = dsAnalyseID.Tables[0].DefaultView;

                            if (dvAnalyseID.Count > 0)
                            {
                                string querySum = "select SUM(ISNULL(Qty, 0)*ISNULL(Price, 0)) as analyseCost from vAnalyseType_Costs where ID=" + dvAnalyseID[0]["ID"].ToString();
                                querySum += "AND CONVERT(DATETIME, '" + Tools.getSQLFormat_103(info.endDate) + "', 103) between startDate AND ISNULL(endDate, CONVERT(DATETIME, '" + Tools.getSQLFormat_103(info.endDate) + "', 103)) AND PaymentTypeID=" + info.strPayType;
                                DataSet dsQuerySum = Hipocrate.DB.DBConnection.GetData(querySum);
                                DataView dvQuerySum = dsQuerySum.Tables[0].DefaultView;

                                tmp = (dvQuerySum.Count > 0 ? (dvQuerySum[0]["analyseCost"] != System.DBNull.Value ? Convert.ToDecimal(dvQuerySum[0]["analyseCost"]) : 0) : 0);
                            }

                            cost = count * tmp;
                            totalCost += cost;

                            sb.Append("<td class='tdn'>" + (cost == 0 ? "-" : cost.ToString("0.00")) + "</td>");
                            cost = 0;
                        }
                        sb.Append("<td class='tdn' >" + (totalCost == 0 ? "0" : totalCost.ToString()) + "</td>");
                        sb.Append("</tr>");
                    }

                    if (dvClass[j]["class"].ToString() == prevClass)
                    {
                        sb.Append("<tr>");
                        sb.Append("<td class='tdnplusleft' colspan='1'>Total " + dvClass[j]["Class"].ToString() + "</td>");
                        sb.Append("<td class='tdnplusleft'>&nbsp;</td>");

                        for (int x = 0; x < dvSections.Count; ++x)
                        {
                            string queryRequestClass = @"select count(*) AS NR from vRequestClass where DeletedID is null and Submited=1";
                            queryRequestClass += " AND Class='" + dvClass[j]["Class"].ToString() + "'";
                            queryRequestClass += " AND SectionCode='" + dvSections[x]["Code"].ToString() + "'";

                            if (info.bSpecifiedPayType)
                                queryRequestClass += " AND PaymentTypeID = " + info.strPayType;
                            if (info.bProcessed)
                                queryRequestClass += " AND status > 0 ";
                            if (info.bTehnice)
                                queryRequestClass += " AND test <> 1 ";

                            queryRequestClass += " AND requestedDate between '" + Tools.getSQLFormat_120(info.startDate) + "' AND '" + Tools.getSQLFormat_120(info.endDate) + "' ";

                            DataSet dsRequestClass = Hipocrate.DB.DBConnection.GetData(queryRequestClass);
                            DataView dvRequestClass = dsRequestClass.Tables[0].DefaultView;

                            if (dvRequestClass.Count > 0)
                                countClass += Convert.ToInt32(dvRequestClass[0]["NR"]);

                            totalCountClass += countClass;
                            sb.Append("<td class='tdnplusright'>" + (countClass == 0 ? "-" : countClass.ToString()) + "</td>");
                            countClass = 0;
                        }

                        sb.Append("<td class='tdnplusright' >" + (totalCountClass == 0 ? "0" : totalCountClass.ToString()) + "</td>");
                        sb.Append("</tr>");
                    }
                }
            }

            sb.Append("</table>");

            sb.Append("</br></br></br>");
            sb.Append("<table border='0' cellpadding='0' cellspacing='0' width='100%' ID='Table3'>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft' colspan='2'>Raspundem de realitatea si exactitatea datelor</td>");
            sb.Append("</tr>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft'>Reprezentant legal al cabinetului</td>");
            sb.Append("<td class='tdright'>Semnatura si parafa medicului</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            phCommonReport.Controls.Add(new LiteralControl(sb.ToString()));

        }
        catch (Exception ex)
        {
            message.Text = ex.ToString();
        }
    }

    protected void listCAS(CommonSession.StareRapoarteLaborator info)
    {
        try
        {
            sb.Append("<table width=\"100%\" border=\"0\">");
            sb.Append("<tr>");
            sb.Append("<td valign=top align=\"left\" valign=\"top\">");
            sb.Append("<span class=\"H3\">Spitalul Clinic de Urgenta pentru Copii 'GRIGORE ALEXANDRESCU'</span>");
            sb.Append("</td>");
            sb.Append("<td valign=top align=\"right\" valign=\"top\">");
            sb.Append(siglaRSC());
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td align=\"center\" colspan=\"2\">");
            sb.Append("<span class=\"H2\">Desfasurator lunar al investigatiilor paraclinice efectuate</span><br>");
            sb.Append("<span class=\"H3\">din " + info.startDate + " pana in " + info.endDate + "</span><br></br>");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            sb.Append("<table border='1' cellpadding='0' cellspacing='0' width='100%' ID='Table1'>");
            sb.Append("<thead>");
            sb.Append("<tr>");
            sb.Append("<td class='tdnplusleft' width='10%'>Nr.<br>cod</td>");
            sb.Append("<td class='tdnplusleft' width='50%'>Tipul investigatiei</td>");
            sb.Append("<td class='tdnplusleft' width='20%'>Total investigatii efectuate</td>");
            sb.Append("<td class='tdnplusleft' width='15%'>Tarif negociat</td>");
            sb.Append("<td class='tdnplusleft' width='15%'>Sume lei total</td>");
            sb.Append("</thead>");
            sb.Append("</tr>");
            sb.Append("<tbody>");

            string queryClass = @"select distinct [Domain] as Class from LAB_DOMAINS WHERE 1=1 ";

            if (info.groupByTypes != "*")
            {
                queryClass += " AND [Domain] in " + info.groupByTypes;
            }

            queryClass += " order by [Domain]";

            DataSet dsClass = Hipocrate.DB.DBConnection.GetData(queryClass.Replace("&nbsp;", " "));
            DataView dvClass = dsClass.Tables[0].DefaultView;
            string prevClass = "";

            if (dvClass.Count > 0)
            {
                decimal totalCount = 0;
                decimal totalCost = 0;

                for (int i = 0; i < dvClass.Count; ++i)
                {
                    if (dvClass[i]["class"].ToString() != prevClass)
                    {
                        prevClass = dvClass[i]["class"].ToString();
                        sb.Append("<tr>");
                        sb.Append("<td class='tdnplusleft' width='100%' colspan='5'>" + dvClass[i]["Class"].ToString() + "</td>");
                        sb.Append("</tr>");
                    }

                    string queryAnalyse = @"select distinct CASName, CASCode from vAnalyseTypes ";
                    queryAnalyse += "where Class='" + dvClass[i]["Class"].ToString() + "'";

                    if (!info.bInactiveToo)
                        queryAnalyse += " AND Active = 1 ";

                    if (!info.bUnpaidToo)
                        queryAnalyse += " AND IsCASPayable = 1 ";

                    queryAnalyse += " order by CASCode, CASName";

                    DataSet dsAnalyse = Hipocrate.DB.DBConnection.GetData(queryAnalyse);
                    DataView dvAnalyse = dsAnalyse.Tables[0].DefaultView;

                    int count = 0;
                    decimal classCost = 0;
                    decimal classCount = 0;
                    decimal cost = 0;

                    if (dvAnalyse.Count > 0)
                    {
                        for (int j = 0; j < dvAnalyse.Count; ++j)
                        {
                            string queryRequestClass = @"select count(*) AS NR from vRequestClass where DeletedID is null and Submited=1";
                            queryRequestClass += " AND CASAnalyseName='" + dvAnalyse[j]["CASName"].ToString() + "'";
                            queryRequestClass += " AND CASAnalyseCode='" + dvAnalyse[j]["CASCode"].ToString() + "'";
                            queryRequestClass += " AND Class='" + dvClass[i]["Class"].ToString() + "'";

                            if (info.groupBySection != "*" && !string.IsNullOrEmpty(info.groupBySection))
                            {
                                queryClass += " AND [SectionCode] in " + info.groupBySection;
                            }

                            if (info.bSpecifiedPayType)
                                queryRequestClass += " AND PaymentTypeID = " + info.strPayType;
                            if (!info.bInactiveToo)
                                queryAnalyse += " AND Active = 1 ";
                            if (!info.bUnpaidToo)
                                queryAnalyse += " AND IsCASPayable = 1 ";
                            if (info.bProcessed)
                                queryRequestClass += " AND Status > 0 ";
                            if (info.bTehnice)
                                queryRequestClass += " AND Test <> 1 ";

                            queryRequestClass += " AND requestedDate between '" + Tools.getSQLFormat_120(info.startDate) + "' AND '" + Tools.getSQLFormat_120(info.endDate) + "' ";
                            queryRequestClass += " group by CASAnalyseName, CASAnalyseCode";

                            DataSet dsRequestClass = Hipocrate.DB.DBConnection.GetData(queryRequestClass);
                            DataView dvRequestClass = dsRequestClass.Tables[0].DefaultView;

                            if (dvRequestClass.Count > 0)
                                count += Convert.ToInt32(dvRequestClass[0]["NR"]);

                            string queryAnalyseID = "select top 1 ID from Analyse_Types where [CASName]='" + dvAnalyse[j]["CASName"].ToString() + "'";
                            DataSet dsAnalyseID = Hipocrate.DB.DBConnection.GetData(queryAnalyseID);
                            DataView dvAnalyseID = dsAnalyseID.Tables[0].DefaultView;

                            if (dvAnalyseID.Count > 0)
                            {
                                string querySum = "select SUM(ISNULL(Qty, 0)*ISNULL(Price, 0)) as analyseCost from vAnalyseType_Costs where ID=" + dvAnalyseID[0]["ID"].ToString();
                                querySum += "AND CONVERT(DATETIME, '" + Tools.getSQLFormat_103(info.endDate) + "', 103) between startDate AND ISNULL(endDate, CONVERT(DATETIME, '" + Tools.getSQLFormat_103(info.endDate) + "', 103)) AND PaymentTypeID=" + info.strPayType;
                                DataSet dsQuerySum = Hipocrate.DB.DBConnection.GetData(querySum);
                                DataView dvQuerySum = dsQuerySum.Tables[0].DefaultView;

                                cost = (dvQuerySum.Count > 0 ? (dvQuerySum[0]["analyseCost"] != System.DBNull.Value ? Convert.ToDecimal(dvQuerySum[0]["analyseCost"]) : 0) : 0);
                            }

                            classCost += cost * count;
                            totalCost += cost * count;

                            classCount += count;
                            totalCount += count;

                            sb.Append("<tr>");
                            sb.Append("<td class='tdnleft'>" + dvAnalyse[j]["CASCode"].ToString() + "</td>");
                            sb.Append("<td class='tdnleft'>" + dvAnalyse[j]["CASName"].ToString() + "</td>");
                            sb.Append("<td class='tdnright'>" + (count == 0 ? "0" : count.ToString()) + "</td>");
                            sb.Append("<td class='tdnright'>" + (cost == 0 ? "0" : cost.ToString("0.00")) + "</td>");
                            sb.Append("<td class='tdnright'>" + (count * cost).ToString("0.00") + "</td>");
                            sb.Append("</tr>");
                        }
                    }

                    if (dvClass[i]["class"].ToString() == prevClass)
                    {
                        sb.Append("<tr>");
                        sb.Append("<td class='tdnplusleft' colspan='2'>Total " + dvClass[i]["Class"].ToString() + "</td>");
                        sb.Append("<td class='tdnright'>" + classCount.ToString() + "</td>");
                        sb.Append("<td class='tdnright' colspan='2'>" + classCost.ToString("0.00") + "</td>");
                        sb.Append("</tr>");
                    }
                }
                sb.Append("<tr>");
                sb.Append("<td class='tdnplusleft' colspan='2'>TOTAL GENERAL</td>");
                sb.Append("<td class='tdnright'>" + totalCount.ToString() + "</td>");
                sb.Append("<td class='tdnright' colspan='2'>" + totalCost.ToString("0.00") + "</td>");
                sb.Append("</tr>");
            }

            sb.Append("</tbody>");
            sb.Append("</table>");

            sb.Append("</br></br></br>");
            sb.Append("<table border='0' cellpadding='0' cellspacing='0' width='100%' ID='Table3'>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft' colspan='2'>Raspundem de realitatea si exactitatea datelor</td>");
            sb.Append("</tr>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft'>Reprezentant legal al cabinetului</td>");
            sb.Append("<td class='tdright'>Semnatura si parafa medicului</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            phCommonReport.Controls.Add(new LiteralControl(sb.ToString()));

        }
        catch (Exception ex)
        {
            message.Text = ex.ToString();
        }
    }

    protected void nominalCAS(CommonSession.StareRapoarteLaborator info)
    {
        try
        {
            sb.Append("<table width=\"100%\" border=\"0\">");
            sb.Append("<tr>");
            sb.Append("<td valign=top align=\"left\" valign=\"top\">");
            sb.Append("<span class=\"H3\">Spitalul Clinic de Urgenta pentru Copii 'GRIGORE ALEXANDRESCU'</span>");
            sb.Append("</td>");
            sb.Append("<td valign=top align=\"right\" valign=\"top\">");
            sb.Append(siglaRSC());
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td align=\"center\" colspan=\"2\">");
            sb.Append("<span class=\"H2\">Lista pacientilor care au efectuat analize de laborator</span><br>");
            sb.Append("<span class=\"H3\">din " + info.startDate + " pana in " + info.endDate + "</span><br></br>");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            sb.Append("<table border='1' cellpadding='0' cellspacing='0' width='100%' ID='Table1'>");
            sb.Append("<thead>");
            sb.Append("<tr>");
            sb.Append("<td class='tdnplus' width='2%'>&nbsp;Nr.<br>Crt</td>");
            sb.Append("<td class='tdnplus' width='5%'>&nbsp;Data<br>efectuarii</td>");
            sb.Append("<td class='tdnplus' width='15%'>&nbsp;Nume pacient</td>");
            sb.Append("<td class='tdnplus' width='5%'>&nbsp;CNP</td>");
            sb.Append("<td class='tdnplus' width='14%'>&nbsp;Medic<br>trimitator</td>");
            sb.Append("<td class='tdnplus' width='3%'>&nbsp;Nr.<br>Contract</td>");
            sb.Append("<td class='tdnplus' width='3%'>&nbsp;Cod<br>parafa</td>");
            sb.Append("<td class='tdnplus' width='45%'>&nbsp;Analize efectuate</td>");
            sb.Append("<td class='tdnplus' width='5%'>&nbsp;Valoare totala<br>analize</td>");
            sb.Append("</tr>");
            sb.Append("</thead>");
            sb.Append("<tbody>");

            string queryPacients = @"select V.ID, convert(varchar(11), V.RequestedDate, 113) as ReqDate, V.LastName, V.FirstName, V.CNP, V.PaymentTypeID,  S.LastName as MedicLastName, 
                S.FirstName as MedicFirstName, S.StampNo, S.ContractNo  from vListLabRequests V left join Staff S on V.MedicID = S.[ID] where V.DeletedID is null and V.Submited=1";

            if (info.strSection != "*" && !string.IsNullOrEmpty(info.strSection))
                queryPacients += " and V.SectionCode in" + info.strSection;

            if (info.groupByTypes != "*" && !string.IsNullOrEmpty(info.groupByTypes))
            {
                queryPacients += " AND exists (SELECT * FROM vAnalyseMachines VM join ANALYSES A on VM.AnalyseID = A.TypeID AND A.RequestID=V.ID AND VM.MachineClass IN " + info.groupByTypes + ") ";
            }

            if (info.startDate != null && info.endDate != null)
                queryPacients += " AND V.RequestedDate BETWEEN '" + Tools.getSQLFormat_120(info.startDate) + "' AND '" + Tools.getSQLFormat_120(info.endDate) + "'";

            if (info.bSpecifiedPayType)
                queryPacients += " AND V.PaymentTypeID = " + info.strPayType;

            queryPacients += "  order by RequestedDate, V.LastName, V.FirstName";

            DataSet dsPacients = Hipocrate.DB.DBConnection.GetData(queryPacients);
            DataView dvPacients = dsPacients.Tables[0].DefaultView;
            List<string> analyseConcat = new List<string>();

            if (dvPacients.Count > 0)
            {
                decimal totalCost = 0;

                for (int i = 0; i < dvPacients.Count; ++i)
                {
                    decimal cost = 0;
                    string queryAnalyseTypes = "";

                    if (info.bInternalCode)
                        queryAnalyseTypes += "select V.TypeID, V.AnalyseCode as Code, V.AnalyseName as Name from vRequestClass V ";
                    else
                        queryAnalyseTypes += "select V.TypeID, V.CASAnalyseCode as Code, V.CASAnalyseName as Name from vRequestClass V ";

                    queryAnalyseTypes += " where RequestID = " + dvPacients[i]["ID"].ToString();

                    if (!info.bInactiveToo)
                        queryAnalyseTypes += " AND V.Active = 1 ";

                    if (!info.bUnpaidToo)
                        queryAnalyseTypes += " AND V.IsCASPayable = 1 ";

                    if (info.groupByTypes != "*")
                        queryAnalyseTypes += " AND V.[Class] IN " + info.groupByTypes + ") ";

                    if (info.bProcessed)
                        queryAnalyseTypes += " AND V.Status > 0 ";

                    if (info.bTehnice)
                        queryAnalyseTypes += " AND V.Test <> 1 ";

                    if (info.bInternalCode)
                        queryAnalyseTypes += " order by V.CASAnalyseCode ";
                    else
                        queryAnalyseTypes += " order by V.CASAnalyseName ";

                    DataSet dsAnalyseTypes = Hipocrate.DB.DBConnection.GetData(queryAnalyseTypes);
                    DataView dvAnalyseTypes = dsAnalyseTypes.Tables[0].DefaultView;

                    for (int j = 0; j < dvAnalyseTypes.Count; ++j)
                    {
                        string querySum = "select SUM(ISNULL(Qty, 0)*ISNULL(Price, 0)) as analyseCost from vAnalyseType_Costs where ID=" + dvAnalyseTypes[j]["TypeID"].ToString();
                        querySum += "AND CONVERT(DATETIME, '" + Tools.getSQLFormat_120(info.endDate) + "', 103) between startDate AND ISNULL(endDate, CONVERT(DATETIME, '" + Tools.getSQLFormat_120(info.endDate) + "', 103)) AND PaymentTypeID=" + info.strPayType;
                        DataSet dsQuerySum = Hipocrate.DB.DBConnection.GetData(querySum);
                        DataView dvQuerySum = dsQuerySum.Tables[0].DefaultView;

                        cost += (dvQuerySum.Count > 0 ? (dvQuerySum[0]["analyseCost"] != System.DBNull.Value ? Convert.ToDecimal(dvQuerySum[0]["analyseCost"]) : 0) : 0);
                        analyseConcat.Add(dvAnalyseTypes[j]["Name"].ToString());
                    }

                    totalCost += cost;

                    sb.Append("<tr>");
                    sb.Append("<td class='tdn' width='2%'>" + (i + 1).ToString() + "</td>");
                    sb.Append("<td class='tdnleft' width='5%'>" + (dvPacients[i]["ReqDate"] != System.DBNull.Value ? dvPacients[i]["ReqDate"].ToString() : "&nbsp;") + "</td>");
                    sb.Append("<td class='tdnleft' width='15%'>" + dvPacients[i]["LastName"].ToString() + " " + dvPacients[i]["FirstName"].ToString() + "</td>");
                    sb.Append("<td class='tdnleft' width='5%'>" + (dvPacients[i]["CNP"] != System.DBNull.Value ? dvPacients[i]["CNP"].ToString() : "&nbsp;") + "</td>");
                    sb.Append("<td class='tdnleft' width='14%'>" + dvPacients[i]["MedicLastName"].ToString() + " " + dvPacients[i]["MedicFirstName"].ToString() + "</td>");
                    sb.Append("<td class='tdnleft' width='3%'>" + (dvPacients[i]["ContractNo"] != System.DBNull.Value ? dvPacients[i]["ContractNo"].ToString() : "&nbsp;") + "</td>");
                    sb.Append("<td class='tdnleft' width='3%'>" + (dvPacients[i]["StampNo"] != System.DBNull.Value ? dvPacients[i]["StampNo"].ToString() : "&nbsp;") + "</td>");
                    sb.Append("<td class='tdnleft' width='45%'>" + analyseConcat.Join(";") + "</td>");
                    sb.Append("<td class='tdnright' width='5%'> " + cost.ToString("0.00") + "</td>");
                    sb.Append("</tr>");

                    analyseConcat.Clear();
                }

                sb.Append("<tr>");
                sb.Append("<td class='tdnplusleft' colspan='8'>TOTAL GENERAL</td>");
                sb.Append("<td class='tdnplusright'>" + totalCost.ToString("0.00") + "</td>");
                sb.Append("</tr>");
            }

            sb.Append("</tbody>");
            sb.Append("</table>");

            sb.Append("</br></br></br>");
            sb.Append("<table border='0' cellpadding='0' cellspacing='0' width='100%' ID='Table3'>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft' colspan='2'>Raspundem de realitatea si exactitatea datelor</td>");
            sb.Append("</tr>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft'>Reprezentant legal al cabinetului</td>");
            sb.Append("<td class='tdright'>Semnatura si parafa medicului</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            phCommonReport.Controls.Add(new LiteralControl(sb.ToString()));

        }
        catch (Exception ex)
        {
            message.Text = ex.ToString();
        }
    }

    protected void listAMBP(CommonSession.StareRapoarteLaborator info)
    {
        try
        {
            sb.Append("<table width=\"100%\" border=\"0\">");
            sb.Append("<tr>");
            sb.Append("<td valign=top align=\"left\" valign=\"top\">");
            sb.Append("<span class=\"H3\">Spitalul Clinic de Urgenta pentru Copii 'GRIGORE ALEXANDRESCU'</span>");
            sb.Append("</td>");
            sb.Append("<td valign=top align=\"right\" valign=\"top\">");
            sb.Append(siglaRSC());
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td align=\"center\" colspan=\"2\">");
            sb.Append("<span class=\"H2\">Centralizator lunar al investigatiilor paraclinice efectuate in ambulatoriul de specialitate pentru asiguratii CASAOPSNAJ</span><br>");
            sb.Append("<span class=\"H3\">din " + info.startDate + " pana in " + info.endDate + "</span><br></br>");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            sb.Append("<table border='1' cellpadding='0' cellspacing='0' width='100%' ID='Table1'>");
            sb.Append("<thead>");
            sb.Append("<tr>");
            sb.Append("<td class='tdnplus' rowspan='2'>&nbsp;COD</td>");
            sb.Append("<td class='tdnplus' rowspan='2'>&nbsp;Tipul investigatiei paraclinice</td>");
            sb.Append("<td class='tdnplus' colspan='2'>Tipul investigatiei paraclinice la recomadarea medicului de familie</td>");
            sb.Append("<td class='tdnplus' colspan='2'>Tipul investigatiei paraclinice la recomadarea medicului de specialitate</td>");
            sb.Append("<td class='tdnplus' rowspan='2'>Tarif/Investigatie paraclinica</td>");
            sb.Append("<td class='tdnplus' colspan='2'>Sume lei</td>");
            sb.Append("<td class='tdnplus' rowspan='2'>Total investigatii paraclinice</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td class='tdnplus'>efectuate</td>");
            sb.Append("<td class='tdnplus'>... din care urgente</td>");
            sb.Append("<td class='tdnplus'>efectuate</td>");
            sb.Append("<td class='tdnplus'>... din care urgente</td>");
            sb.Append("<td class='tdnplus'>TOTAL GENERAL</td>");
            sb.Append("<td class='tdnplus'>... din care urgente</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td class='tdnplus' width='5%'>1</td>");
            sb.Append("<td class='tdnplus' width='40%'>2</td>");
            sb.Append("<td class='tdnplus' width='5%'>3</td>");
            sb.Append("<td class='tdnplus' width='10%'>4</td>");
            sb.Append("<td class='tdnplus' width='5%'>5</td>");
            sb.Append("<td class='tdnplus' width='10%'>6</td>");
            sb.Append("<td class='tdnplus' width='5%'>7</td>");
            sb.Append("<td class='tdnplus' width='5%'>8=(3+5)X7</td>");
            sb.Append("<td class='tdnplus' width='5%'>9=(4+6)X7</td>");
            sb.Append("<td class='tdnplus' width='10%'>10=3+5</td>");
            sb.Append("</tr>");
            sb.Append("</thead>");
            sb.Append("<tbody>");

            string queryClass = @"select distinct [Domain] as Class from LAB_DOMAINS WHERE 1=1 ";

            if (info.groupByTypes != "*")
            {
                queryClass += " AND [Domain] in " + info.groupByTypes;
            }

            queryClass += " order by [Domain]";

            DataSet dsClass = Hipocrate.DB.DBConnection.GetData(queryClass.Replace("&nbsp;", " "));
            DataView dvClass = dsClass.Tables[0].DefaultView;
            string prevClass = "";

            if (dvClass.Count > 0)
            {
                decimal totalCost = 0;
                decimal totalEMGCost = 0;

                int totalCountFamily = 0;
                int totalCountEMGFamily = 0;
                int totalCountSpecialty = 0;
                int totalCountEMGSpecialty = 0;

                for (int i = 0; i < dvClass.Count; ++i)
                {
                    if (dvClass[i]["class"].ToString() != prevClass)
                    {
                        prevClass = dvClass[i]["class"].ToString();
                        sb.Append("<tr>");
                        sb.Append("<td class='tdnplusleft' width='100%' colspan='10'>" + dvClass[i]["Class"].ToString() + "</td>");
                        sb.Append("</tr>");
                    }

                    string queryAnalyse = "";
                    if (info.bInternalCode)
                        queryAnalyse += "select distinct Name, '-' as Code from vAnalyseTypes ";
                    else
                        queryAnalyse += "select distinct CASName as Name, CASCode as Code from vAnalyseTypes ";

                    queryAnalyse += "where Class='" + dvClass[i]["Class"].ToString() + "'";

                    if (!info.bInactiveToo)
                        queryAnalyse += " AND Active = 1 ";

                    if (!info.bUnpaidToo)
                        queryAnalyse += " AND IsCASPayable = 1 ";

                    if (info.bInternalCode)
                        queryAnalyse += " order by Name, Code";
                    else
                        queryAnalyse += " order by CASCode, CASName";

                    DataSet dsAnalyse = Hipocrate.DB.DBConnection.GetData(queryAnalyse);
                    DataView dvAnalyse = dsAnalyse.Tables[0].DefaultView;

                    decimal cost = 0;
                    int countFamily = 0;
                    int countEMGFamily = 0;
                    int countSpecialty = 0;
                    int countEMGSpecialty = 0;

                    if (dvAnalyse.Count > 0)
                    {
                        for (int j = 0; j < dvAnalyse.Count; ++j)
                        {
                            string queryRequestClass = @"select count(*) AS NR, sum(IsEmergency) as EMGNR from vRequestClass where MedicID = (select value from sysconf where Code = 'AMB_FAMILY_MEDIC' and enabled = 1) AND DeletedID IS NULL and Submited=1 ";
                            if (info.bInternalCode)
                                queryRequestClass += " AND AnalyseName='" + dvAnalyse[j]["Name"].ToString() + "'";
                            else
                                queryRequestClass += " AND CASAnalyseName='" + dvAnalyse[j]["Name"].ToString() + "'";
                            queryRequestClass += " AND CASAnalyseCode='" + dvAnalyse[j]["Code"].ToString() + "'";
                            queryRequestClass += " AND Class='" + dvClass[i]["Class"].ToString() + "'";

                            if (info.groupBySection != "*" && !string.IsNullOrEmpty(info.groupBySection))
                            {
                                queryClass += " AND [SectionCode] in " + info.groupBySection;
                            }

                            if (info.bSpecifiedPayType)
                                queryRequestClass += " AND PaymentTypeID = " + info.strPayType;
                            if (!info.bInactiveToo)
                                queryAnalyse += " AND Active = 1 ";
                            if (!info.bUnpaidToo)
                                queryAnalyse += " AND IsCASPayable = 1 ";
                            if (info.bProcessed)
                                queryRequestClass += " AND Status > 0 ";
                            if (info.bTehnice)
                                queryRequestClass += " AND Test <> 1 ";

                            queryRequestClass += " AND requestedDate between '" + Tools.getSQLFormat_120(info.startDate) + "' AND '" + Tools.getSQLFormat_120(info.endDate) + "' ";
                            queryRequestClass += " group by CASAnalyseName, CASAnalyseCode";

                            DataSet dsRequestClass = Hipocrate.DB.DBConnection.GetData(queryRequestClass + " " + queryRequestClass.Replace("MedicID =", "MedicID <>"));
                            DataView dvRequestClass = dsRequestClass.Tables[0].DefaultView;
                            DataView dvRequestClass2 = dsRequestClass.Tables[1].DefaultView;

                            if (dvRequestClass.Count > 0)
                            {
                                countFamily += Convert.ToInt32(dvRequestClass[0]["NR"]);
                                countEMGFamily += Convert.ToInt32(dvRequestClass[0]["EMGNR"]);
                            }

                            if (dvRequestClass2.Count > 0)
                            {
                                countSpecialty += Convert.ToInt32(dvRequestClass2[0]["NR"]);
                                countEMGSpecialty += Convert.ToInt32(dvRequestClass2[0]["EMGNR"]);
                            }

                            string queryAnalyseID = "";
                            if (info.bInternalCode)
                                queryAnalyseID = "select top 1 ID from Analyse_Types where [CASName]='" + dvAnalyse[j]["Name"].ToString() + "'";
                            else
                                queryAnalyseID = "select top 1 ID from Analyse_Types where [Name]='" + dvAnalyse[j]["Name"].ToString() + "'";

                            DataSet dsAnalyseID = Hipocrate.DB.DBConnection.GetData(queryAnalyseID);
                            DataView dvAnalyseID = dsAnalyseID.Tables[0].DefaultView;

                            if (dvAnalyseID.Count > 0)
                            {
                                string querySum = "select SUM(ISNULL(Qty, 0)*ISNULL(Price, 0)) as analyseCost from vAnalyseType_Costs where ID=" + dvAnalyseID[0]["ID"].ToString();
                                querySum += "AND CONVERT(DATETIME, '" + Tools.getSQLFormat_103(info.endDate) + "', 103) between startDate AND ISNULL(endDate, CONVERT(DATETIME, '" + Tools.getSQLFormat_103(info.endDate) + "', 103)) AND PaymentTypeID=" + info.strPayType;
                                DataSet dsQuerySum = Hipocrate.DB.DBConnection.GetData(querySum);
                                DataView dvQuerySum = dsQuerySum.Tables[0].DefaultView;

                                cost = (dvQuerySum.Count > 0 ? (dvQuerySum[0]["analyseCost"] != System.DBNull.Value ? Convert.ToDecimal(dvQuerySum[0]["analyseCost"]) : 0) : 0);
                            }

                            totalCountFamily += countFamily;
                            totalCountEMGFamily += countEMGFamily;
                            totalCountSpecialty += countSpecialty;
                            totalCountEMGSpecialty += countEMGSpecialty;

                            totalCost += (countFamily + countSpecialty) * cost;
                            totalEMGCost += (countEMGFamily + countEMGSpecialty) * cost;

                            sb.Append("<tr>");
                            sb.Append("<td class='tdnleft' width='5%'>" + dvAnalyse[j]["Code"].ToString() + "</td>");
                            sb.Append("<td class='tdnleft' width='40%'>" + dvAnalyse[j]["Name"].ToString() + "</td>");
                            sb.Append("<td class='tdnright' width='5%'>" + countFamily.ToString() + "</td>");
                            sb.Append("<td class='tdnright' width='10%'>" + countEMGFamily.ToString() + "</td>");
                            sb.Append("<td class='tdnright' width='5%'>" + countSpecialty.ToString() + "</td>");
                            sb.Append("<td class='tdnright' width='10%'>" + countEMGSpecialty.ToString() + "</td>");
                            sb.Append("<td class='tdnright' width='5%'>" + cost.ToString("0.00") + "</td>");
                            sb.Append("<td class='tdnright' width='5%'>" + ((countFamily + countSpecialty) * cost).ToString("0.00") + "</td>");
                            sb.Append("<td class='tdnright' width='5%'>" + ((countEMGFamily + countEMGSpecialty) * cost).ToString("0.00") + "</td>");
                            sb.Append("<td class='tdnright' width='10%'>" + (countFamily + countSpecialty) + "</td>");
                            sb.Append("</tr>");

                            countFamily = 0;
                            countEMGFamily = 0;
                            countSpecialty = 0;
                            countEMGSpecialty = 0;
                        }
                    }
                }
                sb.Append("<tr>");
                sb.Append("<td class='tdnplusleft' colspan='2' width='45%'>TOTAL GENERAL</td>");
                sb.Append("<td class='tdnright' width='5%'>" + totalCountFamily.ToString() + "</td>");
                sb.Append("<td class='tdnright' width='10%'>" + totalCountEMGFamily.ToString() + "</td>");
                sb.Append("<td class='tdnright' width='5%'>" + totalCountSpecialty.ToString() + "</td>");
                sb.Append("<td class='tdnright' width='10%'>" + totalCountEMGSpecialty.ToString() + "</td>");
                sb.Append("<td class='tdnright' width='5%'>0</td>");
                sb.Append("<td class='tdnright' width='5%'>" + totalCost.ToString("0.00") + "</td>");
                sb.Append("<td class='tdnright' width='5%'>" + totalEMGCost.ToString("0.00") + "</td>");
                sb.Append("<td class='tdnright' width='10%'>" + (totalCountFamily + totalCountSpecialty).ToString() + "</td>");
                sb.Append("</tr>");
            }

            sb.Append("</tbody>");
            sb.Append("</table>");

            sb.Append("</br></br></br>");
            sb.Append("<table border='0' cellpadding='0' cellspacing='0' width='100%' ID='Table3'>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft' colspan='2'>Raspundem de realitatea si exactitatea datelor</td>");
            sb.Append("</tr>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft'>Reprezentant legal al cabinetului</td>");
            sb.Append("<td class='tdright'>Semnatura si parafa medicului</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            phCommonReport.Controls.Add(new LiteralControl(sb.ToString()));

        }
        catch (Exception ex)
        {
            message.Text = ex.ToString();
        }
    }

    protected void nominalAMBP(CommonSession.StareRapoarteLaborator info)
    {
        try
        {
            sb.Append("<table width=\"100%\" border=\"0\">");
            sb.Append("<tr>");
            sb.Append("<td valign=top align=\"left\" valign=\"top\">");
            sb.Append("<span class=\"H3\">Spitalul Clinic de Urgenta pentru Copii 'GRIGORE ALEXANDRESCU'</span>");
            sb.Append("</td>");
            sb.Append("<td valign=top align=\"right\" valign=\"top\">");
            sb.Append(siglaRSC());
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td align=\"center\" colspan=\"2\">");
            sb.Append("<span class=\"H2\">Lista cu pacientii carora li s-au efectuat investigatii paraclinice in ambulatoriul de specialitate</span><br>");
            sb.Append("<span class=\"H3\">din " + info.startDate + " pana in " + info.endDate + "</span><br></br>");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            sb.Append("<table border='1' cellpadding='0' cellspacing='0' width='100%' ID='Table1'>");
            sb.Append("<thead>");
            sb.Append("<tr>");
            sb.Append("<td class='tdnplus' rowspan='2'>&nbsp;Nr.<br>Crt</td>");
            sb.Append("<td class='tdnplus' rowspan='2'>&nbsp;Data<br>efectuarii</td>");
            sb.Append("<td class='tdnplus' rowspan='2'>&nbsp;Nume pacient</td>");
            sb.Append("<td class='tdnplus' rowspan='2'>&nbsp;CNP pacient</td>");
            sb.Append("<td class='tdnplus' colspan='2'>&nbsp;Bilet de trimitere emis de</td>");
            sb.Append("<td class='tdnplus' colspan='2'>&nbsp;Regim de emitere a BT</td>");
            sb.Append("<td class='tdnplus' rowspan='2'>&nbsp;Lista investigatii</td>");
            sb.Append("<td class='tdnplus' rowspan='2'>&nbsp;Nr investigatii</td>");
            sb.Append("<td class='tdnplus' rowspan='2'>&nbsp;Contravaloare investigatii</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td class='tdnplus'>medic familie (cod parafa)</td>");
            sb.Append("<td class='tdnplus'>medic specialist (cod parafa)</td>");
            sb.Append("<td class='tdnplus'>normal</td>");
            sb.Append("<td class='tdnplus'>in urgenta</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td class='tdnplus' width='2%'>1</td>");
            sb.Append("<td class='tdnplus' width='10%'>2</td>");
            sb.Append("<td class='tdnplus' width='15%'>3</td>");
            sb.Append("<td class='tdnplus' width='8%'>4</td>");
            sb.Append("<td class='tdnplus' width='5%'>5</td>");
            sb.Append("<td class='tdnplus' width='5%'>6</td>");
            sb.Append("<td class='tdnplus' width='5%'>7</td>");
            sb.Append("<td class='tdnplus' width='5%'>8</td>");
            sb.Append("<td class='tdnplus' width='35%'>9</td>");
            sb.Append("<td class='tdnplus' width='5%'>10</td>");
            sb.Append("<td class='tdnplus' width='5%'>11</td>");
            sb.Append("</tr>");
            sb.Append("</thead>");
            sb.Append("<tbody>");

            string queryPacients = @"select V.ID, convert(varchar(11), V.RequestedDate, 113) as ReqDate, V.LastName, V.FirstName, V.CNP, V.PaymentTypeID,  S.LastName as MedicLastName, 
                S.FirstName as MedicFirstName, V.MedicID, S.StampNo, S.ContractNo, V.Priority  from vListLabRequests V left join Staff S on V.MedicID = S.[ID] where V.DeletedID is null and V.Submited=1";

            if (info.strSection != "*" && !string.IsNullOrEmpty(info.strSection))
                queryPacients += " and V.SectionCode in" + info.strSection;

            if (info.groupByTypes != "*" && !string.IsNullOrEmpty(info.groupByTypes))
            {
                queryPacients += " AND exists (SELECT * FROM vAnalyseMachines VM join ANALYSES A on VM.AnalyseID = A.TypeID AND A.RequestID=V.ID AND VM.MachineClass IN " + info.groupByTypes + ") ";
            }

            if (info.startDate != null && info.endDate != null)
                queryPacients += " AND V.RequestedDate BETWEEN '" + Tools.getSQLFormat_120(info.startDate) + "' AND '" + Tools.getSQLFormat_120(info.endDate) + "'";

            if (info.bSpecifiedPayType)
                queryPacients += " AND V.PaymentTypeID = " + info.strPayType;

            queryPacients += "  order by RequestedDate, V.LastName, V.FirstName";

            string medicFamily = "select value from sysconf where Code = 'AMB_FAMILY_MEDIC' and enabled = 1";

            DataSet dsPacients = Hipocrate.DB.DBConnection.GetData(queryPacients + " " + medicFamily);
            DataView dvPacients = dsPacients.Tables[0].DefaultView;
            DataView dvMedicFamily = dsPacients.Tables[1].DefaultView;
            List<string> analyseConcat = new List<string>();

            if (dvPacients.Count > 0)
            {
                int totalCount = 0;
                decimal totalCost = 0;

                for (int i = 0; i < dvPacients.Count; ++i)
                {
                    decimal cost = 0;
                    string queryAnalyseTypes = "";

                    if (info.bInternalCode)
                        queryAnalyseTypes += "select V.TypeID, V.AnalyseCode as Code, V.AnalyseName as Name from vRequestClass V ";
                    else
                        queryAnalyseTypes += "select V.TypeID, V.CASAnalyseCode as Code, V.CASAnalyseName as Name from vRequestClass V ";

                    queryAnalyseTypes += " where RequestID = " + dvPacients[i]["ID"].ToString();

                    if (!info.bInactiveToo)
                        queryAnalyseTypes += " AND V.Active = 1 ";

                    if (!info.bUnpaidToo)
                        queryAnalyseTypes += " AND V.IsCASPayable = 1 ";

                    if (info.groupByTypes != "*")
                        queryAnalyseTypes += " AND V.[Class] IN " + info.groupByTypes + ") ";

                    if (info.bProcessed)
                        queryAnalyseTypes += " AND V.Status > 0 ";

                    if (info.bTehnice)
                        queryAnalyseTypes += " AND V.Test <> 1 ";

                    if (info.bInternalCode)
                        queryAnalyseTypes += " order by V.CASAnalyseCode ";
                    else
                        queryAnalyseTypes += " order by V.CASAnalyseName ";

                    DataSet dsAnalyseTypes = Hipocrate.DB.DBConnection.GetData(queryAnalyseTypes);
                    DataView dvAnalyseTypes = dsAnalyseTypes.Tables[0].DefaultView;

                    for (int j = 0; j < dvAnalyseTypes.Count; ++j)
                    {
                        string querySum = "select SUM(ISNULL(Qty, 0)*ISNULL(Price, 0)) as analyseCost from vAnalyseType_Costs where ID=" + dvAnalyseTypes[j]["TypeID"].ToString();
                        querySum += "AND CONVERT(DATETIME, '" + Tools.getSQLFormat_120(info.endDate) + "', 103) between startDate AND ISNULL(endDate, CONVERT(DATETIME, '" + Tools.getSQLFormat_120(info.endDate) + "', 103)) AND PaymentTypeID=" + info.strPayType;
                        DataSet dsQuerySum = Hipocrate.DB.DBConnection.GetData(querySum);
                        DataView dvQuerySum = dsQuerySum.Tables[0].DefaultView;

                        cost += (dvQuerySum.Count > 0 ? (dvQuerySum[0]["analyseCost"] != System.DBNull.Value ? Convert.ToDecimal(dvQuerySum[0]["analyseCost"]) : 0) : 0);
                        analyseConcat.Add(dvAnalyseTypes[j]["Code"].ToString());
                    }

                    totalCount += dvAnalyseTypes.Count;
                    totalCost += cost;

                    sb.Append("<tr>");
                    sb.Append("<td class='tdn' width='2%'>" + (i + 1).ToString() + "</td>");
                    sb.Append("<td class='tdn' width='5%'>" + (dvPacients[i]["ReqDate"] != System.DBNull.Value ? dvPacients[i]["ReqDate"].ToString() : "&nbsp;") + "</td>");
                    sb.Append("<td class='tdnleft' width='10%'>" + dvPacients[i]["LastName"].ToString() + " " + dvPacients[i]["FirstName"].ToString() + "</td>");
                    sb.Append("<td class='tdn' width='8%'>" + (dvPacients[i]["CNP"] != System.DBNull.Value ? dvPacients[i]["CNP"].ToString() : "&nbsp;") + "</td>");

                    if (dvPacients[i]["MedicID"].ToString() == dvMedicFamily[0]["value"].ToString())
                    {
                        sb.Append("<td class='tdn' width='5%'>----</td>");
                        sb.Append("<td class='tdn' width='5%'>&nbsp;</td>");
                    }
                    else
                    {
                        sb.Append("<td class='tdn' width='5%'>&nbsp;</td>");
                        sb.Append("<td class='tdn' width='5%'>" + dvPacients[i]["StampNo"].ToString() + "</td>");
                    }

                    if (dvPacients[i]["Priority"].ToString() == "0")
                    {
                        sb.Append("<td class='tdn' width='5%'>&nbsp;</td>");
                        sb.Append("<td class='tdn' width='5%'>DA</td>");
                    }
                    else
                    {
                        sb.Append("<td class='tdn' width='5%'>DA</td>");
                        sb.Append("<td class='tdn' width='5%'>&nbsp;</td>");
                    }

                    sb.Append("<td class='tdnleft' width='35%'>" + analyseConcat.Join(";") + "</td>");
                    sb.Append("<td class='tdnright' width='5%'>" + dvAnalyseTypes.Count.ToString() + "</td>");
                    sb.Append("<td class='tdnright' width='5%'>" + cost.ToString("0.00") + "</td>");
                    sb.Append("</tr>");

                    analyseConcat.Clear();
                }

                sb.Append("<tr>");
                sb.Append("<td class='tdnplusleft' colspan='9'>TOTAL GENERAL</td>");
                sb.Append("<td class='tdnplusright'>" + totalCount.ToString() + "</td>");
                sb.Append("<td class='tdnplusright'>" + totalCost.ToString("0.00") + "</td>");
                sb.Append("</tr>");
            }

            sb.Append("</tbody>");
            sb.Append("</table>");

            sb.Append("</br></br></br>");
            sb.Append("<table border='0' cellpadding='0' cellspacing='0' width='100%' ID='Table3'>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft' colspan='2'>Raspundem de realitatea si exactitatea datelor</td>");
            sb.Append("</tr>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft'>Reprezentant legal al cabinetului</td>");
            sb.Append("<td class='tdright'>Semnatura si parafa medicului</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            phCommonReport.Controls.Add(new LiteralControl(sb.ToString()));

        }
        catch (Exception ex)
        {
            message.Text = ex.ToString();
        }
    }

    protected void nominalAMBDetail(CommonSession.StareRapoarteLaborator info)
    {
        try
        {
            sb.Append("<table width=\"100%\" border=\"0\">");
            sb.Append("<tr>");
            sb.Append("<td valign=top align=\"left\" valign=\"top\">");
            sb.Append("<span class=\"H3\">Spitalul Clinic de Urgenta pentru Copii 'GRIGORE ALEXANDRESCU'</span>");
            sb.Append("</td>");
            sb.Append("<td valign=top align=\"right\" valign=\"top\">");
            sb.Append(siglaRSC());
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td align=\"center\" colspan=\"2\">");
            sb.Append("<span class=\"H2\">Lista cu pacientii carora li s-au efectuat investigatii paraclinice in ambulatoriul de specialitate</span><br>");
            sb.Append("<span class=\"H3\">din " + info.startDate + " pana in " + info.endDate + "</span><br></br>");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            sb.Append("<table border='1' cellpadding='0' cellspacing='0' width='100%' ID='Table1'>");
            sb.Append("<thead>");
            sb.Append("<tr>");
            sb.Append("<td class='tdnplus' rowspan='2'>&nbsp;Nr.<br>Crt</td>");
            sb.Append("<td class='tdnplus' rowspan='2'>&nbsp;Data<br>efectuarii</td>");
            sb.Append("<td class='tdnplus' rowspan='2'>&nbsp;Nume pacient</td>");
            sb.Append("<td class='tdnplus' rowspan='2'>&nbsp;CNP pacient</td>");
            sb.Append("<td class='tdnplus' colspan='2'>&nbsp;Bilet de trimitere emis de</td>");
            sb.Append("<td class='tdnplus' colspan='2'>&nbsp;Regim de emitere a BT</td>");
            sb.Append("<td class='tdnplus' rowspan='2'>&nbsp;Lista investigatii</td>");
            sb.Append("<td class='tdnplus' rowspan='2'>&nbsp;Nr investigatii</td>");
            sb.Append("<td class='tdnplus' rowspan='2'>&nbsp;Contravaloare investigatii</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td class='tdnplus'>medic familie (cod parafa)</td>");
            sb.Append("<td class='tdnplus'>medic specialist (cod parafa)</td>");
            sb.Append("<td class='tdnplus'>normal</td>");
            sb.Append("<td class='tdnplus'>in urgenta</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td class='tdnplus' width='2%'>1</td>");
            sb.Append("<td class='tdnplus' width='10%'>2</td>");
            sb.Append("<td class='tdnplus' width='15%'>3</td>");
            sb.Append("<td class='tdnplus' width='8%'>4</td>");
            sb.Append("<td class='tdnplus' width='5%'>5</td>");
            sb.Append("<td class='tdnplus' width='5%'>6</td>");
            sb.Append("<td class='tdnplus' width='5%'>7</td>");
            sb.Append("<td class='tdnplus' width='5%'>8</td>");
            sb.Append("<td class='tdnplus' width='35%'>9</td>");
            sb.Append("<td class='tdnplus' width='5%'>10</td>");
            sb.Append("<td class='tdnplus' width='5%'>11</td>");
            sb.Append("</tr>");
            sb.Append("</thead>");
            sb.Append("<tbody>");

            string queryPacients = @"select V.ID, V.Requested as ReqDate, V.LastName, V.FirstName, V.CNP,  S.LastName as MedicLastName, S.FirstName as MedicFirstName, V.MedicID, 
                S.StampNo, S.ContractNo, V.Priority  from vListLabRequests V left join Staff S on V.MedicID = S.[ID]  where V.DeletedID is null and V.Submited=1";

            if (info.strSection != "*" && !string.IsNullOrEmpty(info.strSection))
                queryPacients += " and V.SectionCode in" + info.strSection;

            if (info.groupByTypes != "*" && !string.IsNullOrEmpty(info.groupByTypes))
            {
                queryPacients += " AND exists (SELECT * FROM vAnalyseMachines VM join ANALYSES A on VM.AnalyseID = A.TypeID AND A.RequestID=V.ID AND VM.MachineClass IN " + info.groupByTypes + ") ";
            }

            if (info.startDate != null && info.endDate != null)
                queryPacients += " AND V.RequestedDate BETWEEN '" + Tools.getSQLFormat_120(info.startDate) + "' AND '" + Tools.getSQLFormat_120(info.endDate) + "'";

            if (info.bSpecifiedPayType)
                queryPacients += " AND V.PaymentTypeID = " + info.strPayType;

            queryPacients += "  order by RequestedDate, V.LastName, V.FirstName";

            string medicFamily = "select value from sysconf where Code = 'AMB_FAMILY_MEDIC' and enabled = 1";

            DataSet dsPacients = Hipocrate.DB.DBConnection.GetData(queryPacients + " " + medicFamily);
            DataView dvPacients = dsPacients.Tables[0].DefaultView;
            DataView dvMedicFamily = dsPacients.Tables[1].DefaultView;
            List<string> analyseConcat = new List<string>();

            if (dvPacients.Count > 0)
            {
                int totalCount = 0;
                decimal totalCost = 0;

                for (int i = 0; i < dvPacients.Count; ++i)
                {
                    decimal cost = 0;
                    string queryAnalyseTypes = "";

                    if (info.bInternalCode)
                        queryAnalyseTypes += "select V.TypeID, V.AnalyseCode as Code, V.AnalyseName as Name from vRequestClass V ";
                    else
                        queryAnalyseTypes += "select V.TypeID, V.CASAnalyseCode as Code, V.CASAnalyseName as Name from vRequestClass V ";

                    queryAnalyseTypes += " where RequestID = " + dvPacients[i]["ID"].ToString();

                    if (!info.bInactiveToo)
                        queryAnalyseTypes += " AND V.Active = 1 ";

                    if (!info.bUnpaidToo)
                        queryAnalyseTypes += " AND V.IsCASPayable = 1 ";

                    if (info.groupByTypes != "*")
                        queryAnalyseTypes += " AND V.[Class] IN " + info.groupByTypes + ") ";

                    if (info.bProcessed)
                        queryAnalyseTypes += " AND V.Status > 0 ";

                    if (info.bTehnice)
                        queryAnalyseTypes += " AND V.Test <> 1 ";

                    if (info.bInternalCode)
                        queryAnalyseTypes += " order by V.CASAnalyseCode ";
                    else
                        queryAnalyseTypes += " order by V.CASAnalyseName ";

                    DataSet dsAnalyseTypes = Hipocrate.DB.DBConnection.GetData(queryAnalyseTypes);
                    DataView dvAnalyseTypes = dsAnalyseTypes.Tables[0].DefaultView;

                    for (int j = 0; j < dvAnalyseTypes.Count; ++j)
                    {
                        string querySum = "select SUM(ISNULL(Qty, 0)*ISNULL(Price, 0)) as analyseCost from vAnalyseType_Costs where ID=" + dvAnalyseTypes[j]["TypeID"].ToString();
                        querySum += "AND CONVERT(DATETIME, '" + Tools.getSQLFormat_120(info.endDate) + "', 103) between startDate AND ISNULL(endDate, CONVERT(DATETIME, '" + Tools.getSQLFormat_120(info.endDate) + "', 103)) AND PaymentTypeID=" + info.strPayType;
                        DataSet dsQuerySum = Hipocrate.DB.DBConnection.GetData(querySum);
                        DataView dvQuerySum = dsQuerySum.Tables[0].DefaultView;

                        cost += (dvQuerySum.Count > 0 ? (dvQuerySum[0]["analyseCost"] != System.DBNull.Value ? Convert.ToDecimal(dvQuerySum[0]["analyseCost"]) : 0) : 0);
                        analyseConcat.Add(dvAnalyseTypes[j]["Code"].ToString());
                    }

                    totalCount += dvAnalyseTypes.Count;
                    totalCost += cost;

                    sb.Append("<tr>");
                    sb.Append("<td class='tdn' width='2%'>" + (i + 1).ToString() + "</td>");
                    sb.Append("<td class='tdn' width='5%'>" + (dvPacients[i]["ReqDate"] != System.DBNull.Value ? dvPacients[i]["ReqDate"].ToString() : "&nbsp;") + "</td>");
                    sb.Append("<td class='tdnleft' width='15%'>" + dvPacients[i]["LastName"].ToString() + " " + dvPacients[i]["FirstName"].ToString() + "</td>");
                    sb.Append("<td class='tdn' width='8%'>" + (dvPacients[i]["CNP"] != System.DBNull.Value ? dvPacients[i]["CNP"].ToString() : "&nbsp;") + "</td>");

                    if (dvPacients[i]["MedicID"].ToString() == dvMedicFamily[0]["value"].ToString())
                    {
                        sb.Append("<td class='tdn' width='5%'>----</td>");
                        sb.Append("<td class='tdn' width='5%'>&nbsp;</td>");
                    }
                    else
                    {
                        sb.Append("<td class='tdn' width='5%'>&nbsp;</td>");
                        sb.Append("<td class='tdn' width='5%'>" + dvPacients[i]["StampNo"].ToString() + "</td>");
                    }

                    if (dvPacients[i]["Priority"].ToString() == "0")
                    {
                        sb.Append("<td class='tdn' width='5%'>&nbsp;</td>");
                        sb.Append("<td class='tdn' width='5%'>DA</td>");
                    }
                    else
                    {
                        sb.Append("<td class='tdn' width='5%'>DA</td>");
                        sb.Append("<td class='tdn' width='5%'>&nbsp;</td>");
                    }

                    sb.Append("<td class='tdnleft' width='35%'>" + analyseConcat.Join(";") + "</td>");
                    sb.Append("<td class='tdnright' width='5%'>" + dvAnalyseTypes.Count.ToString() + "</td>");
                    sb.Append("<td class='tdnright' width='5%'>" + cost.ToString("0.00") + "</td>");
                    sb.Append("</tr>");

                    analyseConcat.Clear();
                }

                sb.Append("<tr>");
                sb.Append("<td class='tdnplusleft' colspan='9'>TOTAL GENERAL</td>");
                sb.Append("<td class='tdnplusright'>" + totalCount.ToString() + "</td>");
                sb.Append("<td class='tdnplusright'>" + totalCost.ToString("0.00") + "</td>");
                sb.Append("</tr>");
            }

            sb.Append("</tbody>");
            sb.Append("</table>");

            sb.Append("</br></br></br>");
            sb.Append("<table border='0' cellpadding='0' cellspacing='0' width='100%' ID='Table3'>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft' colspan='2'>Raspundem de realitatea si exactitatea datelor</td>");
            sb.Append("</tr>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft'>Reprezentant legal al cabinetului</td>");
            sb.Append("<td class='tdright'>Semnatura si parafa medicului</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            phCommonReport.Controls.Add(new LiteralControl(sb.ToString()));

        }
        catch (Exception ex)
        {
            message.Text = ex.ToString();
        }
    }

    protected void generalFilePrepareSecMe(CommonSession.StareRapoarteLaborator info)
    {
        try
        {
            sb.Append("<table width=\"100%\" border=\"0\">");
            sb.Append("<tr>");
            sb.Append("<td valign=top align=\"left\" valign=\"top\">");
            sb.Append("<span class=\"H3\">Spitalul Clinic de Urgenta pentru Copii 'GRIGORE ALEXANDRESCU'</span>");
            sb.Append("</td>");
            sb.Append("<td valign=top align=\"right\" valign=\"top\">");
            sb.Append(siglaRSC());
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td align=\"center\" colspan=\"2\">");
            sb.Append("<span class=\"H2\">CHELTUIELILE MEDICILOR PE FIECARE SECTIE</span><br>");
            sb.Append("<span class=\"H3\">din " + info.startDate + " pana in " + info.endDate + "</span><br></br>");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            sb.Append("<table width='100%' border='0' cellspacing='0' cellpadding='2' class='box1px'>");
            sb.Append("<tr class='tdh'>");
            sb.Append("<td width='1%' nowrap>Data raportului : </td>");
            sb.Append("<td align='left' nowrap>" + DateTime.Now + "</td>");
            sb.Append("<td align='right' nowrap>Utilizator : </td>");
            sb.Append("<td width='1%' nowrap>" + Tools.GetUserName() + "</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            sb.Append("</br>");
            sb.Append("</br>");

            sb.Append("<table border='0' cellpadding='1' cellspacing='0' width='100%' style='padding-top: 10px'>");
            sb.Append("<thead>");
            sb.Append("<tr>");
            sb.Append("<td class='tdnBlock2' width='20%'>Sectie</td>");
            sb.Append("<td class='tdnBlock2' width='75%'>Medic</td>");
            sb.Append("<td class='tdnBlock2' width='5%'>Cost</td>");
            sb.Append("</thead>");
            sb.Append("</tr>");
            sb.Append("<tbody>");
            sb.Append("<tr>");
            sb.Append("<td class='tdn' width='100%' colspan='3'>&nbsp;</td>");
            sb.Append("</tr>");

            string queryMedics = "";

            if (!string.IsNullOrEmpty(info.strMedic))
            {
                queryMedics += @"select distinct sectionName, Medic, sectionCode, MedicID from vSecMeAn where MedicID= " + info.strMedic;
                queryMedics += " AND RequestedDate between CONVERT(smalldatetime, '" + Tools.getSQLFormat_103E(info.startDate) + "', 103) AND CONVERT(smalldatetime, '" + Tools.getSQLFormat_103E(info.endDate) + "', 103) ";
            }
            else
            {
                queryMedics += @"select distinct sectionName, Medic, sectionCode, MedicID from vSecMeAn where ";
                queryMedics += " RequestedDate between CONVERT(smalldatetime, '" + Tools.getSQLFormat_103E(info.startDate) + "', 103) AND CONVERT(smalldatetime, '" + Tools.getSQLFormat_103E(info.endDate) + "', 103) ";
            }

            if (!string.IsNullOrEmpty(info.strSection))
            {
                queryMedics += @" AND (SectionName ='" + info.strSection + "') ";
            }

            queryMedics += " order by sectionName, Medic";

            DataSet dsMedic = Hipocrate.DB.DBConnection.GetData(queryMedics);
            DataView dvMedic = dsMedic.Tables[0].DefaultView;

            if (dvMedic.Count > 0)
            {
                decimal totalMedicCost = 0;
                decimal totalSectionCost = 0;
                string prevSection = "";
                string prevSection2 = "";

                for (int i = 0; i < dvMedic.Count; ++i)
                {
                    if (dvMedic[i]["sectionName"].ToString() != prevSection)
                    {
                        prevSection = dvMedic[i]["sectionName"].ToString();
                        prevSection2 = prevSection;
                        sb.Append("<tr>");
                        sb.Append("<td class='tdnplusleft' width='100%' colspan='5'>" + dvMedic[i]["sectionName"].ToString() + "</td>");
                        sb.Append("</tr>");

                        dvMedic.RowFilter = "sectionName = '" + dvMedic[i]["sectionName"].ToString() + "'";
                        for (int j = 0; j < dvMedic.Count; ++j)
                        {
                            string queryAnalyse = "select typeID, analyseName, count(*) as nr from vAnalyseReport_IDS";
                            queryAnalyse += " where RequestedDate between CONVERT(smalldatetime, '" + Tools.getSQLFormat_103E(info.startDate) + "', 103) AND CONVERT(smalldatetime, '" + Tools.getSQLFormat_103E(info.endDate) + "', 103) ";
                            queryAnalyse += " and sectionCode='" + dvMedic[j]["sectionCode"].ToString() + "' ";
                            queryAnalyse += " and medicID=" + dvMedic[j]["MedicID"].ToString();
                            queryAnalyse += " group by typeID, analyseName";

                            DataSet dsAnalyse = Hipocrate.DB.DBConnection.GetData(queryAnalyse);
                            DataView dvAnalyse = dsAnalyse.Tables[0].DefaultView;

                            for (int k = 0; k < dvAnalyse.Count; ++k)
                            {
                                string querySum = "select SUM(ISNULL(Qty, 0)*ISNULL(Price, 0)) as analyseCost from vAnalyseType_Costs where ID=" + dvAnalyse[k]["typeID"].ToString();
                                querySum += "AND CONVERT(DATETIME, '" + Tools.getSQLFormat_120(info.endDate) + "', 103) between startDate AND ISNULL(endDate, CONVERT(DATETIME, '" + Tools.getSQLFormat_120(info.endDate) + "', 103)) AND PaymentTypeID=" + info.strPayType;
                                DataSet dsQuerySum = Hipocrate.DB.DBConnection.GetData(querySum);
                                DataView dvQuerySum = dsQuerySum.Tables[0].DefaultView;

                                totalMedicCost += (dvQuerySum.Count > 0 ? (dvQuerySum[0]["analyseCost"] != System.DBNull.Value ? Convert.ToDecimal(dvQuerySum[0]["analyseCost"]) : 0) : 0);
                            }

                            totalSectionCost += totalMedicCost;

                            sb.Append("<tr>");
                            sb.Append("<td class='tdnBlock'>&nbsp;</td>");
                            sb.Append("<td class='tdnBlock'>" + dvMedic[j]["Medic"].ToString() + "</td>");
                            sb.Append("<td class='tdnNumber'>" + totalMedicCost.ToString("0.00") + "</td>");
                            sb.Append("</tr>");

                            totalMedicCost = 0;
                        }

                        dvMedic.RowFilter = "";



                        sb.Append("<tr>");
                        sb.Append("<td class='tdnplusleft' colspan='2'>Total pe SECTIA: " + dvMedic[i]["sectionName"].ToString() + "</td>");
                        sb.Append("<td class='tdnplusright'>" + totalSectionCost.ToString("0.00") + "</td>");
                        sb.Append("</tr>");
                        sb.Append("<tr>");
                        sb.Append("<td class='tdn' colspan='3'>&nbsp</td>");
                        sb.Append("</tr>");

                        totalSectionCost = 0;
                    }
                }
            }

            sb.Append("</tbody>");
            sb.Append("</table>");

            sb.Append("</br></br></br>");
            sb.Append("<table border='0' cellpadding='0' cellspacing='0' width='100%' ID='Table3'>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft' colspan='2'>Raspundem de realitatea si exactitatea datelor</td>");
            sb.Append("</tr>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft'>Reprezentant legal al cabinetului</td>");
            sb.Append("<td class='tdright'>Semnatura si parafa medicului</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            phCommonReport.Controls.Add(new LiteralControl(sb.ToString()));
        }
        catch (Exception ex)
        {
            message.Text = ex.ToString();
        }
    }

    protected void generalFilePrepareSecMeAn(CommonSession.StareRapoarteLaborator info)
    {
        try
        {
            sb.Append("<table width=\"100%\" border=\"0\">");
            sb.Append("<tr>");
            sb.Append("<td valign=top align=\"left\" valign=\"top\">");
            sb.Append("<span class=\"H3\">Spitalul Clinic de Urgenta pentru Copii 'GRIGORE ALEXANDRESCU'</span>");
            sb.Append("</td>");
            sb.Append("<td valign=top align=\"right\" valign=\"top\">");
            sb.Append(siglaRSC());
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td align=\"center\" colspan=\"2\">");
            sb.Append("<span class=\"H2\">CHELTUIELILE MEDICILOR PE FIECARE SECTIE SI ANALIZE</span><br>");
            sb.Append("<span class=\"H3\">din " + info.startDate + " pana in " + info.endDate + "</span><br></br>");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            sb.Append("<table width='100%' border='0' cellspacing='0' cellpadding='2' class='box1px'>");
            sb.Append("<tr class='tdh'>");
            sb.Append("<td width='1%' nowrap>Data raportului : </td>");
            sb.Append("<td align='left' nowrap>" + DateTime.Now + "</td>");
            sb.Append("<td align='right' nowrap>Utilizator : </td>");
            sb.Append("<td width='1%' nowrap>" + Tools.GetUserName() + "</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            sb.Append("</br>");
            sb.Append("</br>");

            sb.Append("<table border='0' cellpadding='1' cellspacing='0' width='100%' style='padding-top: 10px'>");
            sb.Append("<thead>");
            sb.Append("<tr>");
            sb.Append("<td class='tdnBlock2' width='15%'>Sectie</td>");
            sb.Append("<td class='tdnBlock2' width='15%'>Medic</td>");
            sb.Append("<td class='tdnBlock2' width='65%'>Analiza</td>");
            sb.Append("<td class='tdnBlock2' width='5%'>Cost</td>");
            sb.Append("</thead>");
            sb.Append("</tr>");
            sb.Append("<tbody>");
            sb.Append("<tr>");
            sb.Append("<td class='tdn' width='100%' colspan='4'>&nbsp;</td>");
            sb.Append("</tr>");

            string queryMedics = "";

            if (!string.IsNullOrEmpty(info.strMedic))
            {
                queryMedics += @"select distinct sectionName, Medic, sectionCode, MedicID from vSecMeAn where MedicID= " + info.strMedic;
                queryMedics += " AND RequestedDate between CONVERT(smalldatetime, '" + Tools.getSQLFormat_103E(info.startDate) + "', 103) AND CONVERT(smalldatetime, '" + Tools.getSQLFormat_103E(info.endDate) + "', 103) ";
            }
            else
            {
                queryMedics += @"select distinct sectionName, Medic, sectionCode, MedicID from vSecMeAn where ";
                queryMedics += " RequestedDate between CONVERT(smalldatetime, '" + Tools.getSQLFormat_103E(info.startDate) + "', 103) AND CONVERT(smalldatetime, '" + Tools.getSQLFormat_103E(info.endDate) + "', 103) ";
            }

            if (!string.IsNullOrEmpty(info.strSection) && !info.strSection.Contains("Toate sectiile"))
            {
                queryMedics += @" AND (SectionName ='" + info.strSection + "') ";
            }

            queryMedics += " order by sectionName, Medic";

            DataSet dsMedic = Hipocrate.DB.DBConnection.GetData(queryMedics);
            DataView dvMedic = dsMedic.Tables[0].DefaultView;

            if (dvMedic.Count > 0)
            {
                decimal totalMedicCost = 0;
                decimal totalSectionCost = 0;
                decimal tempMedicCost = 0;
                string prevSection = "";
                string prevSection2 = "";

                for (int i = 0; i < dvMedic.Count; ++i)
                {
                    if (dvMedic[i]["sectionName"].ToString() != prevSection)
                    {
                        prevSection = dvMedic[i]["sectionName"].ToString();
                        prevSection2 = prevSection;
                        sb.Append("<tr>");
                        sb.Append("<td class='tdnplusleft' width='100%' colspan='5'>" + dvMedic[i]["sectionName"].ToString() + "</td>");
                        sb.Append("</tr>");

                        dvMedic.RowFilter = "sectionName = '" + dvMedic[i]["sectionName"].ToString() + "'";
                        for (int j = 0; j < dvMedic.Count; ++j)
                        {
                            string queryAnalyse = "select typeID, analyseName, count(*) as nr from vAnalyseReport_IDS";
                            queryAnalyse += " where RequestedDate between CONVERT(smalldatetime, '" + Tools.getSQLFormat_103E(info.startDate) + "', 103) AND CONVERT(smalldatetime, '" + Tools.getSQLFormat_103E(info.endDate) + "', 103) ";
                            queryAnalyse += " and sectionCode='" + dvMedic[j]["sectionCode"].ToString() + "' ";
                            queryAnalyse += " and medicID=" + dvMedic[j]["MedicID"].ToString();
                            queryAnalyse += " group by typeID, analyseName";

                            DataSet dsAnalyse = Hipocrate.DB.DBConnection.GetData(queryAnalyse);
                            DataView dvAnalyse = dsAnalyse.Tables[0].DefaultView;

                            sb.Append("<tr>");
                            sb.Append("<td class='tdnBlock'>&nbsp;</td>");
                            sb.Append("<td class='tdnBlock' colspan='2'>" + dvMedic[j]["Medic"].ToString() + "</td>");
                            sb.Append("<td class='tdnNumber'>" + totalMedicCost.ToString("0.00") + "</td>");
                            sb.Append("</tr>");

                            for (int k = 0; k < dvAnalyse.Count; ++k)
                            {
                                string querySum = "select SUM(ISNULL(Qty, 0)*ISNULL(Price, 0)) as analyseCost from vAnalyseType_Costs where ID=" + dvAnalyse[k]["typeID"].ToString();
                                querySum += "AND CONVERT(DATETIME, '" + Tools.getSQLFormat_120(info.endDate) + "', 103) between startDate AND ISNULL(endDate, CONVERT(DATETIME, '" + Tools.getSQLFormat_120(info.endDate) + "', 103)) AND PaymentTypeID=" + info.strPayType;
                                DataSet dsQuerySum = Hipocrate.DB.DBConnection.GetData(querySum);
                                DataView dvQuerySum = dsQuerySum.Tables[0].DefaultView;

                                totalMedicCost += (dvQuerySum.Count > 0 ? (dvQuerySum[0]["analyseCost"] != System.DBNull.Value ? Convert.ToDecimal(dvQuerySum[0]["analyseCost"]) : 0) : 0);
                                tempMedicCost += (dvQuerySum.Count > 0 ? (dvQuerySum[0]["analyseCost"] != System.DBNull.Value ? Convert.ToDecimal(dvQuerySum[0]["analyseCost"]) : 0) : 0);

                                sb.Append("<tr>");
                                sb.Append("<td class='tdnBlock'>&nbsp;</td>");
                                sb.Append("<td class='tdnBlock'>&nbsp;</td>");
                                sb.Append("<td class='tdnBlock'>" + dvAnalyse[k]["analyseName"].ToString() + "</td>");
                                sb.Append("<td class='tdnNumber'>" + (dvQuerySum.Count > 0 ? (dvQuerySum[0]["analyseCost"] != System.DBNull.Value ? Convert.ToDecimal(dvQuerySum[0]["analyseCost"]) : 0) : 0) + "</td>");
                                sb.Append("</tr>");
                            }

                            sb.Append("<tr>");
                            sb.Append("<td class='tdnBlock'>&nbsp;</td>");
                            sb.Append("<td class='tdnBlock' colspan='2'>Total pe medic: " + dvMedic[j]["Medic"].ToString() + "</td>");
                            sb.Append("<td class='tdnNumber'>" + tempMedicCost.ToString("0.00") + "</td>");
                            sb.Append("</tr>");
                            sb.Append("<tr>");
                            sb.Append("<td class='tdnBlock' colspan='4'>&nbsp;</td>");
                            sb.Append("</tr>");

                            totalSectionCost += totalMedicCost;
                            tempMedicCost = 0;
                            totalMedicCost = 0;
                        }

                        dvMedic.RowFilter = "";

                        sb.Append("<tr>");
                        sb.Append("<td class='tdnplusleft' colspan='3'>Total pe SECTIA: " + dvMedic[i]["sectionName"].ToString() + "</td>");
                        sb.Append("<td class='tdnplusright'>" + totalSectionCost.ToString("0.00") + "</td>");
                        sb.Append("</tr>");
                        sb.Append("<tr>");
                        sb.Append("<td class='tdn' colspan='4'>&nbsp</td>");
                        sb.Append("</tr>");

                        totalSectionCost = 0;
                    }
                }
            }

            sb.Append("</tbody>");
            sb.Append("</table>");

            sb.Append("</br></br></br>");
            sb.Append("<table border='0' cellpadding='0' cellspacing='0' width='100%' ID='Table3'>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft' colspan='2'>Raspundem de realitatea si exactitatea datelor</td>");
            sb.Append("</tr>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft'>Reprezentant legal al cabinetului</td>");
            sb.Append("<td class='tdright'>Semnatura si parafa medicului</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            phCommonReport.Controls.Add(new LiteralControl(sb.ToString()));
        }
        catch (Exception ex)
        {
            message.Text = ex.ToString();
        }
    }

    protected void generalFilePrepareSecMeAnDet(CommonSession.StareRapoarteLaborator info)
    {
        try
        {
            sb.Append("<table width=\"100%\" border=\"0\">");
            sb.Append("<tr>");
            sb.Append("<td valign=top align=\"left\" valign=\"top\">");
            sb.Append("<span class=\"H3\">Spitalul Clinic de Urgenta pentru Copii 'GRIGORE ALEXANDRESCU'</span>");
            sb.Append("</td>");
            sb.Append("<td valign=top align=\"right\" valign=\"top\">");
            sb.Append(siglaRSC());
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td align=\"center\" colspan=\"2\">");
            sb.Append("<span class=\"H2\">CHELTUIELILE MEDICILOR PE FIECARE SECTIE</span><br>");
            sb.Append("<span class=\"H3\">din " + info.startDate + " pana in " + info.endDate + "</span><br></br>");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            sb.Append("<table width='100%' border='0' cellspacing='0' cellpadding='2' class='box1px'>");
            sb.Append("<tr class='tdh'>");
            sb.Append("<td width='1%' nowrap>Data raportului : </td>");
            sb.Append("<td align='left' nowrap>" + DateTime.Now + "</td>");
            sb.Append("<td align='right' nowrap>Utilizator : </td>");
            sb.Append("<td width='1%' nowrap>" + Tools.GetUserName() + "</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            sb.Append("</br>");
            sb.Append("</br>");

            sb.Append("<table border='0' cellpadding='1' cellspacing='0' width='100%' style='padding-top: 10px'>");
            sb.Append("<thead>");
            sb.Append("<tr>");
            sb.Append("<td class='tdnBlock2' width='15%'>Sectie</td>");
            sb.Append("<td class='tdnBlock2' width='15%'>Medic</td>");
            sb.Append("<td class='tdnBlock2' width='55%'>Analiza</td>");
            sb.Append("<td class='tdnBlock2' width='5%'>Nr.</td>");
            sb.Append("<td class='tdnBlock2' width='5%'>Pret</td>");
            sb.Append("<td class='tdnBlock2' width='5%'>Total</td>");
            sb.Append("</tr>");
            sb.Append("</thead>");
            sb.Append("<tbody>");
            sb.Append("<tr>");
            sb.Append("<td class='tdn' width='100%' colspan='6'>&nbsp;</td>");
            sb.Append("</tr>");

            string queryMedics = "";
            queryMedics += @"select distinct sectionName, Medic, sectionCode, MedicID from vSecMeAn where ";
            queryMedics += " RequestedDate between CONVERT(smalldatetime, '" + Tools.getSQLFormat_103E(info.startDate) + "', 103) AND CONVERT(smalldatetime, '" + Tools.getSQLFormat_103E(info.endDate) + "', 103) ";

            if (!string.IsNullOrEmpty(info.strSection) && !info.strSection.Contains("Toate sectiile"))
            {
                queryMedics += @" AND (SectionName ='" + info.strSection + "') ";
            }

            if (!string.IsNullOrEmpty(info.strMedic))
            {
                queryMedics += @" and MedicID=" + info.strMedic;
            }

            queryMedics += " order by sectionName, Medic";

            DataSet dsMedic = Hipocrate.DB.DBConnection.GetData(queryMedics);
            DataView dvMedic = dsMedic.Tables[0].DefaultView;

            if (dvMedic.Count > 0)
            {
                decimal totalMedicCost = 0;
                decimal totalSectionCost = 0;
                decimal tempMedicCost = 0;
                string prevSection = "";
                string prevSection2 = "";

                for (int i = 0; i < dvMedic.Count; ++i)
                {
                    if (dvMedic[i]["sectionName"].ToString() != prevSection)
                    {
                        prevSection = dvMedic[i]["sectionName"].ToString();
                        prevSection2 = prevSection;
                        sb.Append("<tr>");
                        sb.Append("<td class='tdnplusleft' width='100%' colspan='6'>" + dvMedic[i]["sectionName"].ToString() + "</td>");
                        sb.Append("</tr>");

                        dvMedic.RowFilter = "sectionName = '" + dvMedic[i]["sectionName"].ToString() + "'";
                        for (int j = 0; j < dvMedic.Count; ++j)
                        {
                            string queryAnalyse = "SELECT A.typeID, A.analyseName, A.ID, A.nr, B.PaymentTypeID From (select typeID, analyseName,id, count(*) as nr from vAnalyseReport_IDS ";
                            queryAnalyse += " where sectionCode='" + dvMedic[j]["sectionCode"].ToString() + "' ";
                            queryAnalyse += " and medicID=" + dvMedic[j]["MedicID"].ToString();
                            queryAnalyse += " and (RequestedDate between CONVERT(smalldatetime, '" + Tools.getSQLFormat_103E(info.startDate) + "', 103) AND CONVERT(smalldatetime, '" + Tools.getSQLFormat_103E(info.endDate) + "', 103)) ";
                            if (!string.IsNullOrEmpty(info.strAnalysis) && info.strAnalysis != "all")
                                queryAnalyse += " and typeId=" + info.strAnalysis;
                            queryAnalyse += "  group by typeID, analyseName, id ) A INNER JOIN ANALYSES B ON A.ID = B.RequestID AND A.typeID = B.TypeID where B.PaymentTypeID=" + info.strPayType;
                            queryAnalyse += " order by analyseName";

                            DataSet dsAnalyse = Hipocrate.DB.DBConnection.GetData(queryAnalyse);
                            DataView dvAnalyse = dsAnalyse.Tables[0].DefaultView;

                            sb.Append("<tr>");
                            sb.Append("<td class='tdnBlock'>&nbsp;</td>");
                            sb.Append("<td class='tdnBlock' colspan='4'>" + dvMedic[j]["Medic"].ToString() + "</td>");
                            sb.Append("<td class='tdnNumber'>" + totalMedicCost.ToString("0.00") + "</td>");
                            sb.Append("</tr>");

                            for (int k = 0; k < dvAnalyse.Count; ++k)
                            {
                                string querySum = "select SUM(ISNULL(Qty, 0)*ISNULL(Price, 0)) as analyseCost from vAnalyseType_Costs where ID=" + dvAnalyse[k]["typeID"].ToString();
                                querySum += "AND CONVERT(DATETIME, '" + Tools.getSQLFormat_120(info.endDate) + "', 103) between startDate AND ISNULL(endDate, CONVERT(DATETIME, '" + Tools.getSQLFormat_120(info.endDate) + "', 103)) AND PaymentTypeID=" + info.strPayType;
                                DataSet dsQuerySum = Hipocrate.DB.DBConnection.GetData(querySum);
                                DataView dvQuerySum = dsQuerySum.Tables[0].DefaultView;

                                totalMedicCost += (dvQuerySum.Count > 0 ? (dvQuerySum[0]["analyseCost"] != System.DBNull.Value ? Convert.ToDecimal(dvQuerySum[0]["analyseCost"]) : 0) : 0);
                                tempMedicCost += (dvQuerySum.Count > 0 ? (dvQuerySum[0]["analyseCost"] != System.DBNull.Value ? Convert.ToDecimal(dvQuerySum[0]["analyseCost"]) : 0) : 0);

                                sb.Append("<tr>");
                                sb.Append("<td class='tdnBlock'>&nbsp;</td>");
                                sb.Append("<td class='tdnBlock'>&nbsp;</td>");
                                sb.Append("<td class='tdnBlock'>" + dvAnalyse[k]["analyseName"].ToString() + "</td>");
                                sb.Append("<td class='tdnBlock'>" + dvQuerySum.Count.ToString() + "</td>");
                                sb.Append("<td class='tdnBlock'>" + (dvQuerySum.Count > 0 ? (dvQuerySum[0]["analyseCost"] != System.DBNull.Value ? Convert.ToDecimal(dvQuerySum[0]["analyseCost"]) : 0) : 0) + "</td>");
                                sb.Append("<td class='tdnNumber'>" + (dvQuerySum.Count > 0 ? (dvQuerySum[0]["analyseCost"] != System.DBNull.Value ? Convert.ToDecimal(dvQuerySum[0]["analyseCost"]) : 0) : 0) + "</td>");
                                sb.Append("</tr>");
                            }

                            sb.Append("<tr>");
                            sb.Append("<td class='tdnBlock'>&nbsp;</td>");
                            sb.Append("<td class='tdnBlock' colspan='4'>Total pe medic: " + dvMedic[j]["Medic"].ToString() + "</td>");
                            sb.Append("<td class='tdnNumber'>" + tempMedicCost.ToString("0.00") + "</td>");
                            sb.Append("</tr>");
                            sb.Append("<tr>");
                            sb.Append("<td class='tdnBlock' colspan='6'>&nbsp;</td>");
                            sb.Append("</tr>");

                            totalSectionCost += totalMedicCost;
                            tempMedicCost = 0;
                            totalMedicCost = 0;
                        }

                        dvMedic.RowFilter = "";

                        sb.Append("<tr>");
                        sb.Append("<td class='tdnplusleft' colspan='5'>Total pe SECTIA: " + dvMedic[i]["sectionName"].ToString() + "</td>");
                        sb.Append("<td class='tdnplusright'>" + totalSectionCost.ToString("0.00") + "</td>");
                        sb.Append("</tr>");
                        sb.Append("<tr>");
                        sb.Append("<td class='tdn' colspan='6'>&nbsp</td>");
                        sb.Append("</tr>");

                        totalSectionCost = 0;
                    }
                }
            }

            sb.Append("</tbody>");
            sb.Append("</table>");

            sb.Append("</br></br></br>");
            sb.Append("<table border='0' cellpadding='0' cellspacing='0' width='100%' ID='Table3'>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft' colspan='2'>Raspundem de realitatea si exactitatea datelor</td>");
            sb.Append("</tr>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft'>Reprezentant legal al cabinetului</td>");
            sb.Append("<td class='tdright'>Semnatura si parafa medicului</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            phCommonReport.Controls.Add(new LiteralControl(sb.ToString()));
        }
        catch (Exception ex)
        {
            message.Text = ex.ToString();
        }
    }

    protected void generalFilePrepareAnSecMe(CommonSession.StareRapoarteLaborator info)
    {
        try
        {
            sb.Append("<table width=\"100%\" border=\"0\">");
            sb.Append("<tr>");
            sb.Append("<td valign=top align=\"left\" valign=\"top\">");
            sb.Append("<span class=\"H3\">Spitalul Clinic de Urgenta pentru Copii 'GRIGORE ALEXANDRESCU'</span>");
            sb.Append("</td>");
            sb.Append("<td valign=top align=\"right\" valign=\"top\">");
            sb.Append(siglaRSC());
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td align=\"center\" colspan=\"2\">");
            sb.Append("<span class=\"H2\">COSTURILE ANALIZELOR PE SECTIE SI PE MEDIC</span><br>");
            sb.Append("<span class=\"H3\">din " + info.startDate + " pana in " + info.endDate + "</span><br></br>");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            sb.Append("<table width='100%' border='0' cellspacing='0' cellpadding='2' class='box1px'>");
            sb.Append("<tr class='tdh'>");
            sb.Append("<td width='1%' nowrap>Data raportului : </td>");
            sb.Append("<td align='left' nowrap>" + DateTime.Now + "</td>");
            sb.Append("<td align='right' nowrap>Utilizator : </td>");
            sb.Append("<td width='1%' nowrap>" + Tools.GetUserName() + "</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            sb.Append("</br>");
            sb.Append("</br>");

            sb.Append("<table border='0' cellpadding='1' cellspacing='0' width='100%' style='padding-top: 10px'>");
            sb.Append("<thead>");
            sb.Append("<tr>");
            sb.Append("<td class='tdnBlock2' width='15%'>Sectie</td>");
            sb.Append("<td class='tdnBlock2' width='15%'>Medic</td>");
            sb.Append("<td class='tdnBlock2' width='65%'>Analiza</td>");
            sb.Append("<td class='tdnBlock2' width='5%'>Cost</td>");
            sb.Append("</thead>");
            sb.Append("</tr>");
            sb.Append("<tbody>");
            sb.Append("<tr>");
            sb.Append("<td class='tdn' width='100%' colspan='4'>&nbsp;</td>");
            sb.Append("</tr>");

            string queryAnalyses = @"select a.[id], a.[name] from analyse_types a where ";
            if (!string.IsNullOrEmpty(info.strAnalysis) && info.strAnalysis != "all")
                queryAnalyses += " a.[id]=" + info.strAnalysis + " and ";
            queryAnalyses += @" exists (select * from vAnSecMe v where v.typeID = a.[id] and ";
            queryAnalyses += @" v.AnPaymentTypeID=" + info.strPayType;
            queryAnalyses += " AND v.RequestedDate between CONVERT(smalldatetime, '" + Tools.getSQLFormat_103E(info.startDate) + "', 103) AND CONVERT(smalldatetime, '" + Tools.getSQLFormat_103E(info.endDate) + "', 103)) ";
            queryAnalyses += " order by [name]";

            DataSet dsAnalyses = Hipocrate.DB.DBConnection.GetData(queryAnalyses);
            DataView dvAnalyses = dsAnalyses.Tables[0].DefaultView;

            if (dvAnalyses.Count > 0)
            {
                decimal medicCost = 0;
                decimal totalMedicCost = 0;
                decimal totalSectionCost = 0;
                string prevAnalyse = "";
                string prevAnalyse2 = "";
                string prevAnalyse3 = "";

                for (int i = 0; i < dvAnalyses.Count; ++i)
                {
                    if (dvAnalyses[i]["name"].ToString() != prevAnalyse)
                    {
                        prevAnalyse = dvAnalyses[i]["name"].ToString();
                        sb.Append("<tr>");
                        sb.Append("<td class='tdnplusleft' width='100%' colspan='5'>" + dvAnalyses[i]["name"].ToString() + "</td>");
                        sb.Append("</tr>");

                        string querySectionMedic = "select sectionName, medic,count(*) as nr from vAnSecMe where typeID=" + dvAnalyses[i]["id"].ToString();
                        querySectionMedic += " and (RequestedDate between CONVERT(smalldatetime, '" + Tools.getSQLFormat_103E(info.startDate) + "', 103) AND CONVERT(smalldatetime, '" + Tools.getSQLFormat_103E(info.endDate) + "', 103)) ";

                        if (!string.IsNullOrEmpty(info.strSection) && !info.strSection.Contains("Toate sectiile"))
                        {
                            querySectionMedic += @" AND SectionName ='" + info.strSection + "' ";
                        }

                        if (!string.IsNullOrEmpty(info.strMedic))
                        {
                            querySectionMedic += @" and MedicID=" + info.strMedic;
                        }

                        querySectionMedic += "  group by sectionName, medic order by sectionName, medic";

                        DataSet dsSectionMedic = Hipocrate.DB.DBConnection.GetData(querySectionMedic);
                        DataView dvSectionMedic = dsSectionMedic.Tables[0].DefaultView;
                        DataView dvSectionMedic2 = dsSectionMedic.Tables[0].DefaultView;
                        int tempContor = 0;
                        int tempDV = 0;

                        for (int j = 0; j < dvSectionMedic.Count; ++j)
                        {
                            string querySum = "select SUM(ISNULL(Qty, 0)*ISNULL(Price, 0)) as analyseCost from vAnalyseType_Costs where ID=" + dvAnalyses[i]["id"].ToString();
                            querySum += "AND CONVERT(DATETIME, '" + Tools.getSQLFormat_120(info.endDate) + "', 103) between startDate AND ISNULL(endDate, CONVERT(DATETIME, '" + Tools.getSQLFormat_120(info.endDate) + "', 103)) AND PaymentTypeID=" + info.strPayType;
                            DataSet dsQuerySum = Hipocrate.DB.DBConnection.GetData(querySum);
                            DataView dvQuerySum = dsQuerySum.Tables[0].DefaultView;

                            medicCost = (dvQuerySum.Count > 0 ? (dvQuerySum[0]["analyseCost"] != System.DBNull.Value ? Convert.ToDecimal(dvQuerySum[0]["analyseCost"]) * (Convert.ToDecimal(dvSectionMedic[j]["nr"])) : 0) : 0);
                            totalMedicCost += (dvQuerySum.Count > 0 ? (dvQuerySum[0]["analyseCost"] != System.DBNull.Value ? Convert.ToDecimal(dvQuerySum[0]["analyseCost"]) * (Convert.ToDecimal(dvSectionMedic[j]["nr"])) : 0) : 0);
                            totalSectionCost += medicCost;

                            if (dvSectionMedic[j]["sectionName"].ToString() != prevAnalyse2 || dvAnalyses[i]["name"].ToString() != prevAnalyse3)
                            {
                                prevAnalyse2 = dvSectionMedic[j]["sectionName"].ToString();
                                prevAnalyse3 = dvAnalyses[i]["name"].ToString();
                                sb.Append("<tr>");
                                sb.Append("<td class='tdnBlock'>&nbsp;</td>");
                                sb.Append("<td class='tdnBlock' colspan='3'>" + dvSectionMedic[j]["sectionName"].ToString() + "</td>");
                                sb.Append("</tr>");
                                dvSectionMedic2.RowFilter = "sectionName = '" + dvSectionMedic[j]["sectionName"].ToString() + "'";
                                tempDV = dvSectionMedic2.Count;
                                dvSectionMedic2.RowFilter = "";
                            }

                            sb.Append("<tr>");
                            sb.Append("<td class='tdnBlock' colspan='2'>&nbsp;</td>");
                            sb.Append("<td class='tdnBlock'>" + dvSectionMedic[j]["Medic"].ToString() + "</td>");
                            sb.Append("<td class='tdnNumber'>" + medicCost.ToString("0.00") + "</td>");
                            sb.Append("</tr>");
                            tempContor++;

                            if (tempContor == tempDV)
                            {
                                sb.Append("<tr>");
                                sb.Append("<td class='tdnBlock'>&nbsp;</td>");
                                sb.Append("<td class='tdnBlock' colspan='2'>Total pe sectia " + dvSectionMedic[j]["sectionName"].ToString() + "</td>");
                                sb.Append("<td class='tdnNumber'>" + totalMedicCost.ToString("0.00") + "</td>");
                                sb.Append("</tr>");
                                tempContor = 0;
                                totalMedicCost = 0;
                            }
                            medicCost = 0;
                        }

                        sb.Append("<tr>");
                        sb.Append("<td class='tdnplusleft' colspan='3'>Total pe analiza: " + dvAnalyses[i]["name"].ToString() + "</td>");
                        sb.Append("<td class='tdnplusright'>" + totalSectionCost.ToString("0.00") + "</td>");
                        sb.Append("</tr>");
                        sb.Append("<tr>");
                        sb.Append("<td class='tdn' colspan='4'>&nbsp</td>");
                        sb.Append("</tr>");
                    }
                    totalSectionCost = 0;
                }
            }

            sb.Append("</tbody>");
            sb.Append("</table>");

            sb.Append("</br></br></br>");
            sb.Append("<table border='0' cellpadding='0' cellspacing='0' width='100%' ID='Table3'>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft' colspan='2'>Raspundem de realitatea si exactitatea datelor</td>");
            sb.Append("</tr>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft'>Reprezentant legal al cabinetului</td>");
            sb.Append("<td class='tdright'>Semnatura si parafa medicului</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            phCommonReport.Controls.Add(new LiteralControl(sb.ToString()));
        }
        catch (Exception ex)
        {
            message.Text = ex.ToString();
        }
    }

    protected void generalFilePrepareAnSecMeDet(CommonSession.StareRapoarteLaborator info)
    {
        try
        {
            sb.Append("<table width=\"100%\" border=\"0\">");
            sb.Append("<tr>");
            sb.Append("<td valign=top align=\"left\" valign=\"top\">");
            sb.Append("<span class=\"H3\">Spitalul Clinic de Urgenta pentru Copii 'GRIGORE ALEXANDRESCU'</span>");
            sb.Append("</td>");
            sb.Append("<td valign=top align=\"right\" valign=\"top\">");
            sb.Append(siglaRSC());
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td align=\"center\" colspan=\"2\">");
            sb.Append("<span class=\"H2\">COSTURILE ANALIZELOR PE SECTIE SI PE MEDIC</span><br>");
            sb.Append("<span class=\"H3\">din " + info.startDate + " pana in " + info.endDate + "</span><br></br>");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            sb.Append("<table width='100%' border='0' cellspacing='0' cellpadding='2' class='box1px'>");
            sb.Append("<tr class='tdh'>");
            sb.Append("<td width='1%' nowrap>Data raportului : </td>");
            sb.Append("<td align='left' nowrap>" + DateTime.Now + "</td>");
            sb.Append("<td align='right' nowrap>Utilizator : </td>");
            sb.Append("<td width='1%' nowrap>" + Tools.GetUserName() + "</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            sb.Append("</br>");
            sb.Append("</br>");

            sb.Append("<thead>");
            sb.Append("<tr>");
            sb.Append("<td class='tdnBlock2' width='15%'>Sectie</td>");
            sb.Append("<td class='tdnBlock2' width='15%'>Medic</td>");
            sb.Append("<td class='tdnBlock2' width='65%'>Analiza</td>");
            sb.Append("<td class='tdnBlock2' width='2%'>Nr.</td>");
            sb.Append("<td class='tdnBlock2' width='3%'>Cost</td>");
            sb.Append("</thead>");
            sb.Append("</tr>");
            sb.Append("<tbody>");
            sb.Append("<tr>");
            sb.Append("<td class='tdn' width='100%' colspan='5'>&nbsp;</td>");
            sb.Append("</tr>");

            string queryAnalyses = @"select a.[id], a.[name] from analyse_types a where ";
            if (!string.IsNullOrEmpty(info.strAnalysis) && info.strAnalysis != "all")
                queryAnalyses += " a.[id]=" + info.strAnalysis + " and ";
            queryAnalyses += @" exists (select * from vAnSecMe v where v.typeID = a.[id] and ";
            queryAnalyses += @" v.AnPaymentTypeID=" + info.strPayType;
            queryAnalyses += " AND v.RequestedDate between CONVERT(smalldatetime, '" + Tools.getSQLFormat_103E(info.startDate) + "', 103) AND CONVERT(smalldatetime, '" + Tools.getSQLFormat_103E(info.endDate) + "', 103)) ";
            queryAnalyses += " order by [name]";

            DataSet dsAnalyses = Hipocrate.DB.DBConnection.GetData(queryAnalyses);
            DataView dvAnalyses = dsAnalyses.Tables[0].DefaultView;

            if (dvAnalyses.Count > 0)
            {
                decimal medicCost = 0;
                decimal totalMedicCost = 0;
                decimal totalSectionCost = 0;
                string prevAnalyse = "";
                string prevAnalyse2 = "";
                string prevAnalyse3 = "";

                for (int i = 0; i < dvAnalyses.Count; ++i)
                {
                    if (dvAnalyses[i]["name"].ToString() != prevAnalyse)
                    {
                        prevAnalyse = dvAnalyses[i]["name"].ToString();
                        sb.Append("<tr>");
                        sb.Append("<td class='tdnplusleft' width='100%' colspan='6'>" + dvAnalyses[i]["name"].ToString() + "</td>");
                        sb.Append("</tr>");

                        string querySectionMedic = "select sectionName, medic,count(*) as nr from vAnSecMe where typeID=" + dvAnalyses[i]["id"].ToString();
                        querySectionMedic += " and (RequestedDate between CONVERT(smalldatetime, '" + Tools.getSQLFormat_103E(info.startDate) + "', 103) AND CONVERT(smalldatetime, '" + Tools.getSQLFormat_103E(info.endDate) + "', 103)) ";

                        if (!string.IsNullOrEmpty(info.strSection) && !info.strSection.Contains("Toate sectiile"))
                        {
                            querySectionMedic += @" AND SectionName ='" + info.strSection + "' ";
                        }

                        if (!string.IsNullOrEmpty(info.strMedic))
                        {
                            querySectionMedic += @" and MedicID=" + info.strMedic;
                        }

                        querySectionMedic += "  group by sectionName, medic order by sectionName, medic";

                        DataSet dsSectionMedic = Hipocrate.DB.DBConnection.GetData(querySectionMedic);
                        DataView dvSectionMedic = dsSectionMedic.Tables[0].DefaultView;
                        DataView dvSectionMedic2 = dsSectionMedic.Tables[0].DefaultView;
                        int tempContor = 0;
                        int tempDV = 0;

                        for (int j = 0; j < dvSectionMedic.Count; ++j)
                        {
                            string querySum = "select SUM(ISNULL(Qty, 0)*ISNULL(Price, 0)) as analyseCost from vAnalyseType_Costs where ID=" + dvAnalyses[i]["id"].ToString();
                            querySum += "AND CONVERT(DATETIME, '" + Tools.getSQLFormat_120(info.endDate) + "', 103) between startDate AND ISNULL(endDate, CONVERT(DATETIME, '" + Tools.getSQLFormat_120(info.endDate) + "', 103)) AND PaymentTypeID=" + info.strPayType;
                            DataSet dsQuerySum = Hipocrate.DB.DBConnection.GetData(querySum);
                            DataView dvQuerySum = dsQuerySum.Tables[0].DefaultView;

                            medicCost = (dvQuerySum.Count > 0 ? (dvQuerySum[0]["analyseCost"] != System.DBNull.Value ? Convert.ToDecimal(dvQuerySum[0]["analyseCost"]) * (Convert.ToDecimal(dvSectionMedic[j]["nr"])) : 0) : 0);
                            totalMedicCost += (dvQuerySum.Count > 0 ? (dvQuerySum[0]["analyseCost"] != System.DBNull.Value ? Convert.ToDecimal(dvQuerySum[0]["analyseCost"]) * (Convert.ToDecimal(dvSectionMedic[j]["nr"])) : 0) : 0);
                            totalSectionCost += medicCost;

                            if (dvSectionMedic[j]["sectionName"].ToString() != prevAnalyse2 || dvAnalyses[i]["name"].ToString() != prevAnalyse3)
                            {
                                prevAnalyse2 = dvSectionMedic[j]["sectionName"].ToString();
                                prevAnalyse3 = dvAnalyses[i]["name"].ToString();
                                sb.Append("<tr>");
                                sb.Append("<td class='tdnBlock'>&nbsp;</td>");
                                sb.Append("<td class='tdnBlock' colspan='4'>" + dvSectionMedic[j]["sectionName"].ToString() + "</td>");
                                sb.Append("</tr>");
                                dvSectionMedic2.RowFilter = "sectionName = '" + dvSectionMedic[j]["sectionName"].ToString() + "'";
                                tempDV = dvSectionMedic2.Count;
                                dvSectionMedic2.RowFilter = "";
                            }

                            sb.Append("<tr>");
                            sb.Append("<td class='tdnBlock' colspan='2'>&nbsp;</td>");
                            sb.Append("<td class='tdnBlock'>" + dvSectionMedic[j]["Medic"].ToString() + "</td>");
                            sb.Append("<td class='tdnNumber'>" + dvSectionMedic[j]["nr"].ToString() + "</td>");
                            sb.Append("<td class='tdnNumber'>" + medicCost.ToString("0.00") + "</td>");
                            sb.Append("</tr>");
                            tempContor++;

                            if (tempContor == tempDV)
                            {
                                sb.Append("<tr>");
                                sb.Append("<td class='tdnBlock'>&nbsp;</td>");
                                sb.Append("<td class='tdnBlock' colspan='3'>Total pe sectia " + dvSectionMedic[j]["sectionName"].ToString() + "</td>");
                                sb.Append("<td class='tdnNumber'>" + totalMedicCost.ToString("0.00") + "</td>");
                                sb.Append("</tr>");
                                tempContor = 0;
                                totalMedicCost = 0;
                            }
                            medicCost = 0;
                        }

                        sb.Append("<tr>");
                        sb.Append("<td class='tdnplusleft' colspan='4'>Total pe analiza: " + dvAnalyses[i]["name"].ToString() + "</td>");
                        sb.Append("<td class='tdnplusright'>" + totalSectionCost.ToString("0.00") + "</td>");
                        sb.Append("</tr>");
                        sb.Append("<tr>");
                        sb.Append("<td class='tdn' colspan='5'>&nbsp</td>");
                        sb.Append("</tr>");
                    }
                    totalSectionCost = 0;
                }
            }

            sb.Append("</tbody>");
            sb.Append("</table>");

            sb.Append("</br></br></br>");
            sb.Append("<table border='0' cellpadding='0' cellspacing='0' width='100%' ID='Table3'>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft' colspan='2'>Raspundem de realitatea si exactitatea datelor</td>");
            sb.Append("</tr>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft'>Reprezentant legal al cabinetului</td>");
            sb.Append("<td class='tdright'>Semnatura si parafa medicului</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            phCommonReport.Controls.Add(new LiteralControl(sb.ToString()));
        }
        catch (Exception ex)
        {
            message.Text = ex.ToString();
        }
    }

    protected void ClassSecMeDet(CommonSession.StareRapoarteLaborator info)
    {
        try
        {
            sb.Append("<table width=\"100%\" border=\"0\">");
            sb.Append("<tr>");
            sb.Append("<td valign=top align=\"left\" valign=\"top\">");
            sb.Append("<span class=\"H3\">Spitalul Clinic de Urgenta pentru Copii 'GRIGORE ALEXANDRESCU'</span>");
            sb.Append("</td>");
            sb.Append("<td valign=top align=\"right\" valign=\"top\">");
            sb.Append(siglaRSC());
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td align=\"center\" colspan=\"2\">");
            sb.Append("<span class=\"H2\">COSTURILE INVESTIGATIILOR PE SECTIE SI PE MEDIC</span><br>");
            sb.Append("<span class=\"H3\">din " + info.startDate + " pana in " + info.endDate + "</span><br></br>");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            sb.Append("<table width='100%' border='0' cellspacing='0' cellpadding='2' class='box1px'>");
            sb.Append("<tr class='tdh'>");
            sb.Append("<td width='1%' nowrap>Data raportului : </td>");
            sb.Append("<td align='left' nowrap>" + DateTime.Now + "</td>");
            sb.Append("<td align='right' nowrap>Utilizator : </td>");
            sb.Append("<td width='1%' nowrap>" + Tools.GetUserName() + "</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            sb.Append("</br>");
            sb.Append("</br>");

            sb.Append("<table border='0' cellpadding='1' cellspacing='0' width='100%' style='padding-top: 10px'>");
            sb.Append("<thead>");
            sb.Append("<tr>");
            sb.Append("<td class='tdnBlock2' width='15%'>Sectie</td>");
            sb.Append("<td class='tdnBlock2' width='15%'>Medic</td>");
            sb.Append("<td class='tdnBlock2' width='63%'>Analiza</td>");
            sb.Append("<td class='tdnBlock2' width='7%'>Cost</td>");
            sb.Append("</thead>");
            sb.Append("</tr>");
            sb.Append("<tbody>");
            sb.Append("<tr>");
            sb.Append("<td class='tdn' width='100%' colspan='4'>&nbsp;</td>");
            sb.Append("</tr>");

            string queryClass = @"select * from vClassSecMe";
            queryClass += " order by Class, SectionName,Medic";

            DataSet dsClass = Hipocrate.DB.DBConnection.GetData(queryClass);
            DataView dvClass = dsClass.Tables[0].DefaultView;

            if (dvClass.Count > 0)
            {
                decimal totalSectionCost = 0;
                decimal totalClassCost = 0;
                string prevClass = "";
                string prevSection = "";
                int tempCLassDV = 0;
                int tempContor = 0;

                for (int i = 0; i < dvClass.Count; ++i)
                {
                    if (dvClass[i]["class"].ToString() != prevClass)
                    {
                        prevClass = dvClass[i]["class"].ToString();
                        sb.Append("<tr>");
                        sb.Append("<td class='tdnplusleft' width='100%' colspan='5'>" + dvClass[i]["class"].ToString() + "</td>");
                        sb.Append("</tr>");
                        dvClass.RowFilter = "class = '" + dvClass[i]["class"].ToString() + "'";
                        tempCLassDV = dvClass.Count;
                        dvClass.RowFilter = "";
                    }

                    if (dvClass[i]["sectionName"].ToString() != prevSection || dvClass[i]["class"].ToString() != prevClass)
                    {
                        prevSection = dvClass[i]["sectionName"].ToString();
                        sb.Append("<tr>");
                        sb.Append("<td class='tdnBlock'>&nbsp;</td>");
                        sb.Append("<td class='tdnBlock' colspan='3'>" + dvClass[i]["sectionName"].ToString() + "</td>");
                        sb.Append("</tr>");

                        dvClass.RowFilter = "class = '" + prevClass + "' and sectionName = '" + prevSection + "'";
                        int tmpCost = 0;

                        for (int j = 0; j < dvClass.Count; ++j)
                        {
                            tmpCost = dvClass[j]["cost"] != System.DBNull.Value ? Convert.ToInt32(dvClass[j]["cost"]) : 0;
                            sb.Append("<tr>");
                            sb.Append("<td class='tdnBlock' colspan='2'>&nbsp;</td>");
                            sb.Append("<td class='tdnBlock'>" + dvClass[j]["Medic"].ToString() + "</td>");
                            sb.Append("<td class='tdnNumber'>" + tmpCost.ToString("0.00") + "</td>");
                            sb.Append("</tr>");
                            totalSectionCost += tmpCost; 
                        }

                        dvClass.RowFilter = "";

                        sb.Append("<tr>");
                        sb.Append("<td class='tdnBlock'>&nbsp;</td>");
                        sb.Append("<td class='tdnBlock' colspan='2'>Total pe sectia " + dvClass[i]["sectionName"].ToString() + "</td>");
                        sb.Append("<td class='tdnNumber'>" + totalSectionCost.ToString("0.00") + "</td>");
                        sb.Append("</tr>");

                        totalClassCost += totalSectionCost;
                        totalSectionCost = 0;
                    }

                    tempContor++;

                    if (tempContor == tempCLassDV)
                    {
                        sb.Append("<tr>");
                        sb.Append("<td class='tdnplusleft' colspan='3'>Total pe: " + dvClass[i]["class"].ToString() + "</td>");
                        sb.Append("<td class='tdnplusright'>" + totalClassCost.ToString("0.00") + " ROL</td>");
                        sb.Append("</tr>");
                        sb.Append("<tr>");
                        sb.Append("<td class='tdn' colspan='4'>&nbsp</td>");
                        sb.Append("</tr>");
                        tempContor = 0;
                        totalClassCost = 0;
                    }
                }
            }

            sb.Append("</tbody>");
            sb.Append("</table>");

            sb.Append("</br></br></br>");
            sb.Append("<table border='0' cellpadding='0' cellspacing='0' width='100%' ID='Table3'>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft' colspan='2'>Raspundem de realitatea si exactitatea datelor</td>");
            sb.Append("</tr>");
            sb.Append("<tr height='40'>");
            sb.Append("<td class='tdleft'>Reprezentant legal al cabinetului</td>");
            sb.Append("<td class='tdright'>Semnatura si parafa medicului</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            phCommonReport.Controls.Add(new LiteralControl(sb.ToString()));
        }
        catch (Exception ex)
        {
            message.Text = ex.ToString();
        }
    }
}
